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

myCustomDbContext' can't be converted to service type 'Microsoft.AspNetCore.Identity.IUserStore`1[erp_colombia.Entities.Employee]'


I want to make IdentityDbContext and Have a custom user type of employee. But when I start the app I get this error

"ArgumentException: Implementation type 'erp_colombia.erp_colombiaDbContext' can't be converted to service type 'Microsoft.AspNetCore.Identity.IUserStore`1[erp_colombia.Entities.Employee]'"  How can I fix this problem thank you very much.

Here is the line in my asp.net core startup.cs file that is causing problems.

services.AddIdentityCore<Employee>().AddUserStore<erp_colombiaDbContext>();

Here is what my Employee class looks like

[Table("erp_empleados")]
    public class Employee : IdentityUser
    {

        public string Name { get; set; }
        public string FamilyName { get; set; }
        //AND MANY MORE FIELDS....    
    }

Here is what my custom dbContext looks like

  public class erp_colombiaDbContext : IdentityDbContext
    {

        public erp_colombiaDbContext(DbContextOptions options) : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
        }

        public DbSet<Employee> Employees { get; set; }
        public DbSet<Menu> Menus { get; set; }
        //ADD MANY MORE DbSets
    }
    
    
    
     

Solution

  • I had to change

    services.AddIdentityCore<Employee>().AddUserStore<erp_colombiaDbContext>();
    

    to

    services.AddIdentityCore<Employee>().AddEntityFrameworkStores<erp_colombiaDbContext>();