Search code examples
c#asp.net-coreasp.net-identity

Customizing Identity for .NetCore


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.

enter image description here

What am I missing?


Solution

  • 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; }
    }