身份更改GUID为int

如何将AspNetUser表的PK列从guid更改为int数据类型?
现在可以使用今天发布的最新的asp.net身份版本.

但是我找不到任何地方怎么办?

解决方法

认情况下,ASP.NET身份(使用实体框架)使用字符串作为主键,而不是GUID,但它会将GUID存储在这些字符串中.

您需要定义更多的类,我刚刚创建了一个新项目(我正在使用VS2013 Update 2 CTP),以下是需要更改的身份模型:

public class ApplicationUser : IdentityUser<int,ApplicationUserLogin,ApplicationUserRole,ApplicationUserClaim>
{
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationoptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this,DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }
}

public class ApplicationUserRole : IdentityUserRole<int>
{
}

public class ApplicationUserLogin : IdentityUserLogin<int>
{
}

public class ApplicationUserClaim : IdentityUserClaim<int>
{
}

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

public class ApplicatonUserStore :
    UserStore<ApplicationUser,ApplicationRole,int,ApplicationUserClaim>
{
    public ApplicatonUserStore(ApplicationDbContext context)
        : base(context)
    {
    }
}

public class ApplicationDbContext
    : IdentityDbContext<ApplicationUser,ApplicationUserClaim>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }
}

您还需要更新其他几个地方,只需按照编译错误,最常见的更改将是将从User.Identity.GetUserId()返回的字符串转换为整数.

另外,在回答another question(我没有问过这个问题的时候),我提供了一个例子,解决这个问题,看看下面的资料库:

https://github.com/JSkimming/AspNet.Identity.EntityFramework.Multitenant

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...