c# - Asp.net 标识 : Why the clustered index is on guid (nvarchar) column and how to change this?

标签 c# asp.net sql-server asp.net-identity

Asp.net 标识将主键创建为带有聚集索引的 nvarchar(128)。 基于http://www.sqlskills.com/blogs/kimberly/guids-as-primary-keys-andor-the-clustering-key/我也想要

  1. 更新我的应用程序,使聚集索引列位于 int 上
  2. 将主键存储从 guid 更改为 int。

您有什么建议? 如果第一个解决方案是可行的,那么 Entity Framework 是否提供了一种实现方法?
ASP.NET Identity - How to change the dbo.AspNetUsers.Id into a nonclustered index?唯一的办法

最佳答案

对于 #2,如果您不需要(或不想)使用 GUID 作为主键,您可以像这样将它们更改为整数:

public class ApplicationUser : IdentityUser<int, ApplicationUserLogin, 
    ApplicationUserRole, ApplicationUserClaim>
{
}

public class ApplicationUserLogin : IdentityUserLogin<int>
{
}

public class ApplicationUserClaim : IdentityUserClaim<int>
{
}

public class ApplicationRole : IdentityRole<int, ApplicationUserRole>
{
}

public class ApplicationUserRole : IdentityUserRole<int>
{
}

然后像这样声明你的 DbContext:

public class MyContext: IdentityDbContext<ApplicationUser, ApplicationRole, int,
  ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> 
{
}

关于c# - Asp.net 标识 : Why the clustered index is on guid (nvarchar) column and how to change this?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27942950/

相关文章:

c# - 循环缓冲区的用途是什么?

c# - 需要帮助跨 UI 线程和 C# 中的另一个线程获取信息

c# - .Net TimezoneInfo.ConvertTime UTC 日期到萨摩亚返回的值不正确

javascript - 从 RadDateTimePicker 中扣除天数

C#。 NPOCO。错误 : "Incorrect syntax near ' &'. " when trying to join

c# - LINQ to Entities 跳过并采取

c# - ASP.NET HTTPClient 获取等待激活的请求状态

asp.net - 如何启用连接:Keep-Alive for aps.net core 2.1

sql-server - 有没有办法从 sqlcmd 获取当前正在执行的文件?

sql-server - SQL Server - 如何拆分多个列中字符的字符串