【发布时间】:2019-05-13 22:45:26
【问题描述】:
我是 dot-net core 2.x 的新手,所以...
我想将 asp.net core 2.2 IdentityUser 中的 Id 类型从 string 更改为 int。
我通过 google(和 stackoverflow 搜索工具)找到的所有示例都为我提供了 asp.net core 2.0 的示例,它在您搭建身份时提供 ApplicationUser(2.2 没有提供)。
所以,我不知所措.. 我尝试的第一件事(我寄予厚望)是:
services.AddDefaultIdentity<IdentityUser<int>>()
.AddRoles<IdentityRole>()
.AddDefaultTokenProviders()
.AddEntityFrameworkStores<ApplicationDbContext>();
但是,当我尝试 Add-Migration InitialCreate -Context ApplicationDbContext 时出现以下错误:
访问“程序”类上的 IWebHost 时出错。在没有应用程序服务提供商的情况下继续。错误:GenericArguments[0],“Microsoft.AspNetCore.Identity.IdentityUser`1[System.Int32]”,在“Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9[TUser,TRole,TContext,TKey,TUserClaim,TUserRole, TUserLogin,TUserToken,TRoleClaim]' 违反了 'TUser' 类型的约束
想法?想法?我可以阅读的文档?
【问题讨论】:
-
@TanvirArjel 我已经回滚了您的编辑,这使得 OP 看起来还要求更改 Role 类型的类型,但事实并非如此。
标签: c# asp.net-core asp.net-core-identity asp.net-core-2.2