Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Identity remove column from AspNetUsers table

When I use ASP.NET Identity first code approach, I want to generate columns in AspNetUsers table in my own way. I don't need to have stored multiple columns with null values. I just need columns Id, SecurityStamp and UserName. Only post, that I've found is here: AspNet Identity 2.0 Email and UserName duplication , but it is still unsloved (due to error in Santosh comment).

So can anybody tell my how to solve this?

EDIT: Is it even possible to delete some of these columns/properties?

Thanks

like image 318
exeq Avatar asked Aug 29 '14 00:08

exeq


1 Answers

Actually you can ignore the fields, just you need to configure your entity OnModelCreating within your context Class as:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<IdentityUser>().Ignore(c => c.AccessFailedCount)
                                           .Ignore(c=> c.LockoutEnabled)
                                           .Ignore(c=>c.LockoutEndDateUtc)
                                           .Ignore(c=>c.Roles)
                                           .Ignore(c=>c.TwoFactorEnabled);//and so on...

        modelBuilder.Entity<IdentityUser>().ToTable("Users");//to change the name of table.

}
like image 136
Aashish Kumar Avatar answered Oct 04 '22 17:10

Aashish Kumar