Reputation: 6755
I am trying to customize Identity and I'm getting the following error when trying to have my DbContextClass inherit from IdentityUser:
Severity Code Description Project File Line Suppression State Error CS0311 The type 'CustomerManager.Domain.User' cannot be used as type parameter 'TUser' in the generic type or method 'IdentityDbContext'. There is no implicit reference conversion from 'CustomerManager.Domain.User' to 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser'. CustomerManager.Data E:\Clients\DMFA\CustomerManager\CustomerManager.Data\CustomerManagerContext.cs 9 Active
User Class:
public class User : IdentityUser<long, UserLogin, UserRole, UserClaim>
{
public string FirstName { get; set; }
public string LastNme { get; set; }
}
DbContext Class:
public class CustomerManagerContext : IdentityDbContext<User>
{
public CustomerManagerContext(DbContextOptions<CustomerManagerContext> options) : base(options)
{
}
}
UserLogin Class:
public class UserLogin : IdentityUserLogin<long>
{
}
UserRole Class:
public class UserRole : IdentityUserRole<long>
{
}
UserClaim Class:
public class UserClaim : IdentityUserClaim<long>
{
}
Despite what I think to be correct I get the above error in my DbContext Class.
What am I missing?
Upvotes: 0
Views: 463
Reputation: 2961
You may want to start simpler and then work your way to more complexity. I hope this helps!
public class User : IdentityUser<long>
{
public string FirstName { get; set; }
public string LastNme { get; set; }
}
Upvotes: 3
Reputation: 7812
Since you have customized User and Role Your CustomerManagementContext definition should look like below.
public class CustomerManagementContext : IdentityDbContext<User, IdentityRole<long>, long, UserLogin,UserRole,UserClaim>{}
Upvotes: 0