Naigel
Naigel

Reputation: 9644

Asp.net Identity 2 custom user and custom table name

I'm trying to customize IdentityUser with a couple of extra fields

public class User : IdentityUser 
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

And changing the name of the table

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
{
    base.OnModelCreating(modelBuilder);
    modelBuilder.Entity<IdentityUser>().ToTable("Auth_Users", "web");
    modelBuilder.Entity<User>().ToTable("Auth_Users", "web");
}

Pretty straightforward, it works, I have my table web.Auth_Users. The bad thing is that the other tables containing user id, so AspNetUsersClaim, AspNetUserLogins and AspNetUsersRole, add a column named IdentityUser_Id that is always set to NULL

enter image description here

Why? Where does it come from and how can I avoid it to be created?

Upvotes: 1

Views: 606

Answers (1)

CodeNotFound
CodeNotFound

Reputation: 23200

You are getting this weird column because of this line modelBuilder.Entity<IdentityUser>().ToTable("Auth_Users", "web");

Just remove it. Finally you must have this code :

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
{
    base.OnModelCreating(modelBuilder);
    modelBuilder.Entity<User>().ToTable("Auth_Users", "web");
}

Upvotes: 2

Related Questions