Why do I have two tables - AspNetUsers and ApplicationUser

asp.net-identity c# entity-framework-core

Question

I am new to ASP.NET Core MVC and EF. I created a CatchmebgUser, which inherits IdentityUser. I added a custom field for a photo in CatchmebgUser and applied the migrations.

Now I have two tables: AspNetUsers and CatchmebgUser.

When using the User object I was getting data from the AspNetUsers table until I added this line to CatchmebgContext:

builder.Entity<CatchmebgUser>().ToTable("CatchmebgUser");

Is there a way to get rid of the AspNetUsers table or I should have two separate tables for the users?

1
0
1/10/2019 10:44:59 PM

Accepted Answer

If you inherit a custom User type from IdentityUser, you must instead use a derived version of IdentityDbContext, which allows you to specify this concrete types for user, role and primary keys used throughout the identity framework:

public class MyDbContext : IdentityDbContext<CatchmebgUser, IdentityRole, string>
{
   ...
}

This way you don't have to add builder.Entity<CatchmebgUser>().ToTable("CatchmebgUser") configuration for your type, as the context will automatically use DbSet<CatchmebgUser> for the Users property.

2
1/10/2019 12:26:12 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow