How to change type of id in Microsoft.AspNet.Identity.EntityFramework.IdentityUser

后端 未结 5 890
既然无缘
既然无缘 2020-11-27 10:44

(ASP.NET MVC 5, EF6, VS2013)

I\'m trying to figure out how to change the type of the \"Id\" field from string to int in the type:

Mi         


        
5条回答
  •  半阙折子戏
    2020-11-27 11:04

    @HaoKung

    I've succeeded to make int id's with your nightly builds. User.Identity.GetUserId() problem is still there, but i just did int.parse() for now.

    The biggest suprise was that i did not need to create ID by myself, db was made with identity id and it was somehow automatically set for new users Oo...

    Model:

        public class ApplicationUser : IdentityUser
    {
        public ApplicationUser()
        {
        }
        public ApplicationUser(string name) : this() { UserName = name; }
    }
    
    public class ApplicationDbContext : IntUserContext
    {
        public ApplicationDbContext()
        {
    
        }
    }
    
    private class IntRole : IdentityRole
    {
        public IntRole()
        {
        }
        public IntRole(string name) : this() { Name = name; }
    }
    private class IntUserRole : IdentityUserRole { }
    private class IntUserClaim : IdentityUserClaim { }
    private class IntUserLogin : IdentityUserLogin { }
    private class IntUserContext : IdentityDbContext
    {
        public IntUserContext()
            : base("DefaultConnection")
        {
    
        }
    }
    private class IntUserStore : UserStore
    {
        public IntUserStore(DbContext context)
            : base(context)
        {
    
        }
    }
    private class IntRoleStore : RoleStore
    {
        public IntRoleStore(DbContext context)
            : base(context)
        {
        }
    }
    

    Controller:

            public AccountController()
            : this(new UserManager(new IntUserStore(new ApplicationDbContext())))
        {
        }
    
        public AccountController(UserManager userManager)
        {
            UserManager = userManager;
        }
    
        public UserManager UserManager { get; private set; }
    

    Hope release build will come soon :D...

    P.S. Can't write comments so i did an answer, sorry.

提交回复
热议问题