我想将用户id的数据类型从string更改为long。现在我有:
//ApplicationUser.cs
public class ApplicationUser : IdentityUser<long>
{
//some additional properties
}
public class ApplicationRole : IdentityRole<long>
{
}
//Startup.cs
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
//DbContext setup
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
//authentications, cookies and others
}
}
//ApplicationDbContext.cs
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, long>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
//fluent apis
}
//DBsets
}
正如
this tutorial
. 但我在运行应用程序时遇到了这个错误。
TypeLoadException: GenericArguments[1], 'Microsoft.AspNetCore.Identity.IdentityRole', on
'Microsoft.AspNetCore.Identity.UserStoreBase`8[TUser,TRole,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken,TRoleClaim]'
violates the constraint of type parameter 'TRole'.
我的理解是,ApplicationRole类型在创建UserStoreBase实例时是无效的,但从来没有想到如何逃脱。
我环顾四周,发现了一些文件,如
this
,但它是2.0之前的版本,我不需要修改标识中的所有内容。这个过程中可能有什么错误?教程还不够吗?