Reputation: 91
I'm trying to add Identity Services.
And I'm trying to change the number of columns in the user table. I don't know how to correct it.
When I change
// IT DOESN'T WORK
services.AddIdentityCore<User>()
.AddEntityFrameworkStores<ApplicationContext>();
to
// this works
services.AddIdentityCore<IdentityUser>()
.AddEntityFrameworkStores<ApplicationContext>();
Code:
// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentityCore<User>().AddEntityFrameworkStores<ApplicationContext>();
services.AddRazorPages();
}
public class User : IdentityUser
{
public int Year { get; set; }
}
Upvotes: 2
Views: 7899
Reputation: 36595
Try to change like below:
services.AddDefaultIdentity<User>()
.AddEntityFrameworkStores<ApplicationDbContext>();
Be sure your DbContext like below:
public class ApplicationDbContext : IdentityDbContext<User>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
}
}
Be sure update _LoginPartial.cshtml
and replace IdentityUser
with User
:
@inject SignInManager<User> SignInManager
@inject UserManager<User> UserManager
Finally,you could scarffold the Identity.
Upvotes: 4