aspnet / Identity

[Archived] ASP.NET Core Identity is the membership system for building ASP.NET Core web applications, including membership, login, and user data. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
1.96k stars 868 forks source link

Can't configure Identity #1864

Closed CeelMarten closed 6 years ago

CeelMarten commented 6 years ago

I have a class ApplicationUser witch inherited from IdentityUser

    public class ApplicationUser : IdentityUser<long>
    {
    }

and I want to use it in ApplicationDbContext

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }

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

Visual Studio says that I can't use ApplicationUser because there is no implicit reference conversion from ApplicationUser to IdentityUser. I found this in github where

      services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext, long>()
                .AddDefaultTokenProviders();

the solution is to change code from
.AddEntityFrameworkStores<ApplicationDbContext>() to .AddEntityFrameworkStores<ApplicationDbContext, long>() but there is not overload for this method

CeelMarten commented 6 years ago

I found the solution. Just Inherit ApplicationUserfrom IdentityUser<long>, ApplicationUserRolefrom IdentityUserRole<long> then use public class ApplicationDbContext : IdentityDbContext<ApplicationUser,IdentityRole<long>,long>