如何从Asp.Net Identity表中删除descriminator列

时间:2015-05-27 19:07:21

标签: c# sql asp.net-mvc entity-framework asp.net-identity

我重命名了标准身份表:

    public class User : IdentityUser
    {
        //...
        public string Name { get; set; }
        public string Surname { get; set; }
        public DateTime? RegisteredDate { get; set; }
        public DateTime? LastLoginDate { get; set; }
        //...
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<IdentityUser>().ToTable("Users");
        modelBuilder.Entity<User>().ToTable("Users");
        modelBuilder.Entity<IdentityRole>().ToTable("Roles");
        modelBuilder.Entity<Role>().ToTable("Roles");
        modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
        modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
        modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");
    }

得到了这个:

Error One

modelBuilder中删除此列需要做什么?

1 个答案:

答案 0 :(得分:3)

Table-Per-Hierarchy继承方案中使用了Discriminator列。

Code First必须添加一个特殊列来区分持久类。这不是对象模型中持久化类的属性;它由EF Code First内部使用。默认情况下,列名为Discriminator,其类型为字符串。值默认为持久化类名称 - 在本例中为User More info

<强>更新

如果您不想要该列,则可以通过在您的上下文中添加User来使IdentityUser模型的一部分不是DbSet<User>

modelBuilder.Entity<User>().ToTable("Users");