我正在使用带有
Asp.net Identity的MVC6项目,并希望将ID列从字符串更改为INT.我关注这篇文章
enter link description here
我得到一个错误,说可以在Role和User的ID列中插入一个null,但是如果我恢复到它的标准就可以了.
public class ApplicationUser : IdentityUser<int> { } public class ApplicationRole : IdentityRole<int> { } public class ApplicationDbContext : IdentityDbContext<ApplicationUser,ApplicationRole,int> { protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); // Customize the ASP.NET Identity model and override the defaults if needed. // For example,you can rename the ASP.NET Identity table names and more. // Add your customizations after calling base.OnModelCreating(builder); } public DbSet<PropertyManagementCompany> PMC { get; set; } }
解决方法
我之前为MVC5做过这个,之前是我实际做的
#region Entities public class ApplicationUserClaim : IdentityUserClaim<Int32> { } public class ApplicationUserRole : IdentityUserRole<Int32> { } public class ApplicationUserLogin : IdentityUserLogin<Int32> { } public class ApplicationRole : IdentityRole<Int32,ApplicationUserRole> { } public class ApplicationUser : IdentityUser<Int32,ApplicationUserLogin,ApplicationUserRole,ApplicationUserClaim>,IUser<Int32> { } public class ApplicationClaimsPrincipal : ClaimsPrincipal { public ApplicationClaimsPrincipal(ClaimsPrincipal claimsPrincipal) : base(claimsPrincipal) { } public Int32 UserId { get { return Int32.Parse(this.FindFirst(ClaimTypes.Sid).Value); } } } #endregion #region Stores public class ApplicationUserStore : UserStore<ApplicationUser,Int32,ApplicationUserClaim> { public ApplicationUserStore() : base(new CustomsSiteDbContext()) { } public ApplicationUserStore(CustomsSiteDbContext context) : base(context) { } } public class ApplicationRoleStore : RoleStore<ApplicationRole,ApplicationUserRole> { public ApplicationRoleStore() : base(new CustomsSiteDbContext()) { } public ApplicationRoleStore(CustomsSiteDbContext context) : base(context) { } } #endregion #region Managers public class ApplicationUserManager : UserManager<ApplicationUser,Int32> { public ApplicationUserManager() : base(new ApplicationUserStore()) { } public ApplicationUserManager(ApplicationUserStore userStore) : base(userStore) { } } public class ApplicationRoleManager : RoleManager<ApplicationRole,Int32> { public ApplicationRoleManager() : base(new ApplicationRoleStore()) { } public ApplicationRoleManager(ApplicationRoleStore roleStore) : base(roleStore) { } } #endregion
我希望这有帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。