Search code examples
c#asp.net-coreasp.net-identityapi-authorization

There is no implicit reference conversion from 'KCA.Core.Models.Employee' to 'Microsoft.AspNetCore.Identity.IdentityUser'


I am creating a asp.net core application using clean architecture and I am getting this error in my DbContext (KCAContext) The type 'KCA.Core.Models.Employee' cannot be used as type parameter 'TUser' in the generic type or method 'ApiAuthorizationDbContext'. There is no implicit reference conversion from 'KCA.Core.Models.Employee' to 'Microsoft.AspNetCore.Identity.IdentityUser'.

This is the start of the class public class KCAContext : ApiAuthorizationDbContext, IKCAContext { public KCAContext(DbContextOptions options, IOptions operationalStoreOptions) : base(options, operationalStoreOptions) { }

and this is the employee model public class Employee : IdentityUser<Guid!>

I have added the appropriate services to the startup file and tried using a user interface which inherits from IdentityUser but I am still getting the same issue, is there any simple way to rectify this error?


Solution

  • From this discussion https://github.com/dotnet/aspnetcore/issues/9548 ,They are not going to support. enter image description here I tried some code with IdentityDbContext which running with no errors maybe you can reference.
    You can also check this answer The type ApplicationUser cannot be used as type parameter 'TUser' in the generic type or method 'IdentityDbContext<TUser>'
    Employee.cs

    using Microsoft.AspNetCore.Identity;
    
    namespace WebApplication27
    {
        public class Employee : IdentityUser<Guid>
        {
    
        }
    }
    

    EmployeeRole

    using Microsoft.AspNetCore.Identity;
    
    namespace WebApplication27
    {
        public class EmployeeRole : IdentityRole<Guid>
        {
        }
    }
    

    Program.cs

    builder.Services.AddIdentity<KCAContext, EmployeeRole>();
    

    KCAContext.cs

    using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
    using Microsoft.EntityFrameworkCore;
    
    
    namespace WebApplication27
    {
        public class KCAContext : IdentityDbContext<Employee,EmployeeRole,Guid>
        {
            public KCAContext(DbContextOptions<KCAContext> options)
             : base(options)
            {
            }
    
        }
    }