【发布时间】:2019-11-28 19:57:43
【问题描述】:
得到this code sample成功运行后,我尝试将Identity User Id类型更改为Guid:
public class AppUser : IdentityUser<Guid>
{
public string Name { get; set; }
}
我在数据库上下文中遇到错误
public class AppIdentityDbContext : IdentityDbContext<AppUser>
{
public AppIdentityDbContext(DbContextOptions<AppIdentityDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
说:
类型“AuthServer.Infrastructure.Data.Identity.AppUser”不能用作类型参数“TUser” 泛型类型或方法“IdentityDbContext”。没有 从 'AuthServer.Infrastructure.Data.Identity.AppUser' 到隐式引用转换 'Microsoft.AspNetCore.Identity.IdentityUser'
猜测该项目中的 Identity Server 没有使用 Asp.Net 角色,我尝试了一种解决方法,方法是创建一个从 IdentityRole 继承的空 AppRole 类,并按如下方式使用它:
public class AppIdentityDbContext : IdentityDbContext<AppUser, AppRole, Guid>
错误停止显示,但在删除迁移文件夹并重新创建新的初始迁移后,我收到以下错误:
访问“程序”类上的 IWebHost 时出错。 在没有应用程序服务提供商的情况下继续。错误: GenericArguments1, 'Microsoft.AspNetCore.Identity.IdentityRole', on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9[TUser,TRole,TContext,TKey,TUserClaim,TUserRole,TUserLogin,TUserToken,TRoleClaim]' 违反了“TRole”类型的约束。
那么有什么办法呢?
【问题讨论】:
标签: c# asp.net-core entity-framework-core asp.net-identity identityserver4