asp.net mvc将自定义列添加到身份角色表

时间:2018-10-09 16:56:17

标签: 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 CustomId{ get; set; }
}

在dbContext中,我添加了

 modelBuilder.Entity<ApplicationRole>().ToTable("AspNetRoles");

使用此方法,使用迁移将新列CustomId成功添加到AspNetRoles表中。
但是当我不得不像这样调用角色表时

private readonly IdentityDbContext db_Identity;
..
..
 db_Identity.Roles.Select(x=>x.CustomId) 

在这里找不到新添加的列CustomId
我错过了任何一步吗?

更新

有了@Chirs的回答,我可以获得CoustomId,但是当我运行时,出现了这个错误

Cannot create a DbSet for 'IdentityRole' because this type is not included in the model for the context

1 个答案:

答案 0 :(得分:1)

如果使用自定义身份模型,则还需要从通用for bookie in bookies: df[bookie + "_kelly"] = df[bookie].apply(kelly_criterion(df[bookie],df["win"])) 类之一继承并在适当的类型参数中指定自定义类型。在这种情况下,您只需要以下内容:

TypeError: 'Series' object is not callable

然后使用您的自定义上下文类:

IdentityDbContext