Eis Karlsson
Eis Karlsson

Reputation: 78

Why do I have two tables - AspNetUsers and ApplicationUser

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?

Upvotes: 1

Views: 1197

Answers (1)

Martin Zikmund
Martin Zikmund

Reputation: 39072

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.

Upvotes: 3

Related Questions