[英]The entity type 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<string>' requires a key to be defined
All was working fine until I introduced Identity. 在介绍Identity之前,一切工作正常。
I changed my context class to be: 我将上下文类更改为:
public partial class VisualJobsDbContext : IdentityDbContext<ApplicationUser>
{
private IConfigurationRoot _config;
public VisualJobsDbContext() { }
public VisualJobsDbContext(IConfigurationRoot config, DbContextOptions options) : base(options)
{
_config = config;
}...
and I have a Generic repository that is declared in the form: 我有一个通用存储库,该存储库以以下形式声明:
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>();
}....
The Error occurs on the 错误发生在
this.dbSet = context.Set<>(); this.dbSet = context.Set <>();
the first time it gets hit. 第一次被击中。 My OnModelCreating method does get called. 我的OnModelCreating方法确实被调用了。 The page I'm trying to get to from my MVC app does not require a login as it is a general page, but there will be areas that will require a login. 我想从我的MVC应用程序访问的页面不需要登录,因为它是常规页面,但是有些区域需要登录。 However, I dont get as far as my controller Constructor method before it errors. 但是,在错误发生之前,我并没有深入了解我的控制器Constructor方法。 To Register the service I have: 要注册服务,我有:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<VisualJobsDbContext>()
.AddDefaultTokenProviders();
and I can step this ok. 我可以迈出这一步。
any ideas what I'm missing? 有什么想法我想念的吗? I have looked at this stackoverflow answer and others, but it doesn't really help 我已经看过这个stackoverflow答案和其他答案 ,但这并没有真正的帮助
In my OnModelCreating Method. 在我的OnModelCreating方法中。 I needed to place base.OnModelCreating(modelBuilder);
我需要放置base.OnModelCreating(modelBuilder);
as my first line of code. 作为我的第一行代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.