我已將代碼從 ASP.NET Core 2.0 升級到 Core 2.1。我創建了一個新的 Core 2.1 項目并將我的代碼移動到新項目中。我提供了我的初創公司的樣本和ApplicationDbContext嘗試登錄時出現以下錯誤無法為“IdentityUser”創建 DbSet,因為此類型未包含在上下文的模型中。Microsoft.EntityFrameworkCore.Internal.InternalDbSet.get_EntityType()啟動文件//Core 2.1 services.AddDefaultIdentity<IdentityUser>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); ////Old Core 2.0 Code //services.AddIdentity<ApplicationUser, IdentityRole>() // .AddEntityFrameworkStores<ApplicationDbContext>() // .AddDefaultTokenProviders();應用程序數據庫上下文.cspublic partial class ApplicationDbContext : IdentityDbContext<ApplicationUser>{ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { Database.EnsureCreated(); } }
3 回答

喵喔喔
TA貢獻1735條經驗 獲得超5個贊
從您的 startup.cs 更改
services.AddDefaultIdentity<IdentityUser>()
到
services.AddDefaultIdentity<ApplicationUser>()

守著一只汪
TA貢獻1872條經驗 獲得超4個贊
作為跟進:為了避免下一個可能的問題,一旦這里得到修復:您還必須更改 Views\Shared_LoginPartial.cshtml
從
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
到
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
- 3 回答
- 0 關注
- 265 瀏覽
添加回答
舉報
0/150
提交
取消