0

We are trying to map the ASPNetUsers table to our custom table users. Below are the classes and their relationship.

public partial class Users     
{  
    public int Id { get; set; }       
    public string FirstName { get; set; }       
    public string MiddleName { get; set; }        
    public string LastName { get; set; }        
    public string UserInfoId { get; set; }    
    public virtual AspNetUsers UserInfo { get; set; }
}

public class ApplicationUser : IdentityUser
{
    public virtual Users Users { get; set; }
}

When we are implementing the identity using these models, we get the below error:

"Cannot use table 'AspNetUsers' in schema '' for entity 'AspNetUsers' since it is being used for another entity."

We have not done any changes in the ASPNetUsers tables; it is same as we got through the migration.

How can we fix this?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Dimple Sharma
  • 21
  • 1
  • 4
  • Possible duplicate of [link](http://stackoverflow.com/questions/34575020/cannot-use-table-aspnetusers-in-schema-for-entity-aspnetusers-since-it-is) – Rupa Mistry Feb 10 '17 at 12:07

1 Answers1

5

In your ApplicationDbContext you have to customize the AspNetUsers table:

protected override void OnModelCreating(ModelBuilder builder)
{
    base.OnModelCreating(builder);
    new AspNetUsersConfiguration(builder.Entity<AspNetUsers>());
}

And in your Configuration file:

public class AspNetUsersConfiguration
{
    public AspNetUsersConfiguration(EntityTypeBuilder<AspNetUsers> entity)
    {
     entity.ToTable("AspNetUsers", "dbo");
     entity.HasKey(e => e.Id);
    }
}

The key answer is in define a schema dbo to table AspNetUsers.

MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59
FelipeMSaboya
  • 51
  • 1
  • 2