Here's how to use an integer column in Identity, Asp NET Core, and Entity Framework Core:
public class User : IdentityUser<int>
{
}
public class Role : IdentityRole<int>
{
}
public class AppDbContext : IdentityDbContext<User, Role, int>
{
public AppDbContext(DbContextOptions options) : base(options) {}
}
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<User, Role>(options => {
// ...
}).AddEntityFrameworkStores<AppDbContext, int>(); // NOTE this line
}
}
:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: GenericArguments[0], '...Models.User', on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`3[TUser,TRole,TContext]' violates the constraint of type 'TUser'. ---> System.TypeLoadException: GenericArguments[0], '...Models.User', on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`4[TUser,TRole,TContext,TKey]' violates the constraint of type parameter 'TUser'.
, TKey AddEntityFrameworkStores<AppDbContext, int>()
.