I recently decided to implement ASP.NET Identity functionality on a website that I am developing in ASP.NET Core MVC.
Let me take a quick look at the tables and classes in the topic:
public class User : IdentityUser
{
public string FirstName { get; set; }
public stirng LastName { get; set; }
public int CountryId { get; set; }
public Country Country { get; set; }
}
public class Country
{
public int Id { get; set; }
public string ISO { get; set; }
public string Name { get; set; }
}
The class is Countrysomewhat irrelevant, but in case you need a link from the class User.
Using this setting, I configured my database context as follows:
public class DatabaseContext : IdentityDbContext<User>
{
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<IdentityUser>.ToTable("User");
builder.Entity<IndentityRole>.ToTable("Roles");
builder.Entity<IdentityUserRole<string>>.ToTable("UserRoles");
builder.Entity<IdentityUserClaim<string>>.ToTable("UserClaims");
builder.Entity<IdentityUserLogin<string>>.ToTable("UserLogins");
}
}
I use custom tables (renamed) and map them as follows.
Problem
Now, when I run my project, the first time I call the database that I create, I get the following error:
The User object type must be inferred from IdentityUser to reflect the hierarchy of the corresponding CLR types.
, User IdentityUser, , ? , User IdentityUser?