Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete descriminator column from Asp.Net Identity tables

I renamed the standard identity tables:

    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");
    }

and got this:

Error One

What do I need to do in modelBuilder to drop this column?

like image 382
Eugene Chybisov Avatar asked Oct 19 '22 10:10

Eugene Chybisov


1 Answers

The Discriminator column is used and required in Table-Per-Hierarchy inheritance scenarios.

Code First has to add a special column to distinguish between persistent classes. This isn’t a property of the persistent class in our object model; it’s used internally by EF Code First. By default, the column name is Discriminator, and its type is string. The values defaults to the persistent class names —in this case, User.
More info

Update

If you don't want that column, you can make User part of the model not IdentityUser for instance by adding a DbSet<User> to your context:

modelBuilder.Entity<User>().ToTable("Users");
like image 155
Sirwan Afifi Avatar answered Oct 22 '22 00:10

Sirwan Afifi