0

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?

4
  • Why does your IdentityUser have all of the <long, UserLogin, UserRole, UserClaim> properties on it? I don't think you need all of that. Commented May 25, 2017 at 0:11
  • @NovaDev see PankajKapare answer Commented May 25, 2017 at 0:20
  • you may want to start simpler and then work your way to more complexity. The answer below that you pointed to doesn't answer the question about why you want add those properties in that fashion... Commented May 25, 2017 at 0:27
  • 1
    @NovaDev you are absolutely right. answer the question to claim your credit. Commented May 25, 2017 at 0:35

2 Answers 2

3

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; }
}
Sign up to request clarification or add additional context in comments.

Comments

0

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>{}

1 Comment

After the changes it still says the User class is not convertible to an IdentityUser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.