[英]The entity type 'Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin<string>' requires a key to be defined
[英]The entity type 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<string>' requires a key to be defined
在介紹Identity之前,一切工作正常。
我將上下文類更改為:
public partial class VisualJobsDbContext : IdentityDbContext<ApplicationUser>
{
private IConfigurationRoot _config;
public VisualJobsDbContext() { }
public VisualJobsDbContext(IConfigurationRoot config, DbContextOptions options) : base(options)
{
_config = config;
}...
我有一個通用存儲庫,該存儲庫以以下形式聲明:
public abstract class GenericRepository<C,T> : IGenericRepository<T> where T : class where C : IdentityDbContext<ApplicationUser>, new()
{
private C _entities = new C();
private VisualJobsDbContext context;
private DbSet<T> dbSet;
public GenericRepository(VisualJobsDbContext context)
{
this.context = context;
this.dbSet = context.Set<T>();
}....
錯誤發生在
this.dbSet = context.Set <>();
第一次被擊中。 我的OnModelCreating方法確實被調用了。 我想從我的MVC應用程序訪問的頁面不需要登錄,因為它是常規頁面,但是有些區域需要登錄。 但是,在錯誤發生之前,我並沒有深入了解我的控制器Constructor方法。 要注冊服務,我有:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<VisualJobsDbContext>()
.AddDefaultTokenProviders();
我可以邁出這一步。
有什么想法我想念的嗎? 我已經看過這個stackoverflow答案和其他答案 ,但這並沒有真正的幫助
在我的OnModelCreating方法中。 我需要放置base.OnModelCreating(modelBuilder);
作為我的第一行代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.