Les*_*s P 8 c# asp.net-core-2.1
我已将代码从ASP.NET Core 2.0升级到Core 2.1.我创建了一个新的Core 2.1项目,并将我的代码移到了新项目中.我提供了我的启动和样本ApplicationDbContext
尝试登录时出现以下错误
无法为"IdentityUser"创建DbSet,因为此类型未包含在上下文的模型中.Microsoft.EntityFrameworkCore.Internal.InternalDbSet.get_EntityType()
startup.cs
//Core 2.1
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
////Old Core 2.0 Code
//services.AddIdentity<ApplicationUser, IdentityRole>()
// .AddEntityFrameworkStores<ApplicationDbContext>()
// .AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
ApplicationDbContext.cs
public partial class ApplicationDbContext :
IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext>
options)
: base(options)
{
Database.EnsureCreated();
}
}
Run Code Online (Sandbox Code Playgroud)
我查看了以下Microsoft文章:https: //blogs.msdn.microsoft.com/webdev/2018/05/30/asp-net-core-2-1-0-now-available/
https://docs.microsoft.com/en-us/aspnet/core/migration/20_21?view=aspnetcore-2.1
小智 6
从您的startup.cs更改
services.AddDefaultIdentity<IdentityUser>()
Run Code Online (Sandbox Code Playgroud)
至
services.AddDefaultIdentity<ApplicationUser>()
Run Code Online (Sandbox Code Playgroud)
作为跟进:为了避免下一个可能的问题,一旦这里得到修复:您还必须更改 Views\Shared_LoginPartial.cshtml
从
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
Run Code Online (Sandbox Code Playgroud)
到
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10612 次 |
| 最近记录: |