entity-framework – 带有INT id列的MVC 6的ASP.Net标识
发布时间:2020-12-16 06:39:32 所属栏目:asp.Net 来源:网络整理
导读:我正在使用带有 Asp.net Identity的MVC6项目,并希望将ID列从字符串更改为INT.我关注这篇文章 enter link description here 我得到一个错误,说可以在Role和User的ID列中插入一个null,但是如果我恢复到它的标准就可以了. public class ApplicationUser : Ident
我正在使用带有
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 我希望这有帮助 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-3 – 我的路由如何使用ASP MVC3在URL中间使用可
- asp.net – 是否可以并行运行iis6和iis7?
- asp.net – 如何在ASP文本框中显示会话值
- asp.net – 标签导航 – 框架还是AJAX?
- asp.net – IIS 7似乎正在删除显式设置的内容类型.我怎么能
- asp.net – 将JSON对象反序列化为列表不能使用asmx服务
- ABP官方文档(八)【会话管理】
- asp.net-core – 设置.NET Core项目的版本号
- 是否有必要创建ASP.NET 4.0 SQL会话状态数据库,与现有的ASP
- asp.net-mvc – ASP.Net MVC:控制器中的访问验证错误消息?
推荐文章
站长推荐
热点阅读