Asp.net core mvc asp.net mvc将自定义列添加到标识角色表
这就是我如何向标识角色表添加新列的方法Asp.net core mvc asp.net mvc将自定义列添加到标识角色表,asp.net-core-mvc,identityserver4,Asp.net Core Mvc,Identityserver4,这就是我如何向标识角色表添加新列的方法 public class ApplicationRole : IdentityRole { public ApplicationRole() : base() { } public ApplicationRole(string name, long customId) : base(name) { this.CustomId= customId; } public virtual long Cust
public class ApplicationRole : IdentityRole
{
public ApplicationRole() : base() { }
public ApplicationRole(string name, long customId) : base(name)
{
this.CustomId= customId;
}
public virtual long CustomId{ get; set; }
}
在dbContext中,我添加了
modelBuilder.Entity<ApplicationRole>().ToTable("AspNetRoles");
我在这里找不到新添加的列CustomId
。有没有我错过的一步 更新 使用@Chirs的答案,我可以得到
CoustomId
,但是当我运行时,我得到了这个错误
Cannot create a DbSet for 'IdentityRole' because this type is not included in the model for the context
如果您使用的是自定义标识模型,则还需要继承其中一个泛型
IdentityDbContext
类,并在相应的类型参数中指定自定义类型。在这种情况下,您只需要以下内容:
public class MyDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
如果您使用的是自定义标识模型,则还需要继承其中一个泛型
IdentityDbContext
类,并在相应的类型参数中指定自定义类型。在这种情况下,您只需要以下内容:
public class MyDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
这真的很有帮助,另外,请解释为什么
TKey
保留为string
,我们应该在什么时候定义它?:)当我运行无法为“IdentityRole”创建DbSet时,我遇到了这个错误,因为上下文的模型中没有包含这种类型的DbSet
,这真的很有帮助,另外,请解释为什么TKey
保留为字符串,我们应该在什么时候为它定义?:)当我运行无法为'IdentityRole'创建DbSet时,我遇到了这个错误,因为上下文的模型中不包括这种类型
private readonly MyDbContext db_Identity;