简体   繁体   English

实体类型&#39;Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin <string> &#39;需要定义一个密钥

[英]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.

相关问题 实体类型 &#39;Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin<string> &#39; 需要定义一个键 - The entity type 'Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin<string>' requires a key to be defined 实体类型'IdentityUserLogin<string> ' 需要在添加索引时定义主键</string> - The entity type 'IdentityUserLogin<string>' requires a primary key to be defined when adding index 实体类型&#39;IdentityUserLogin<string> &#39; 需要定义一个主键。 如果您打算使用无密钥实体类型,请在 - The entity type 'IdentityUserLogin<string>' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in Microsoft.AspNetCore.Mvc.Rendering.SelectListGroup&#39;需要定义一个主键 - Microsoft.AspNetCore.Mvc.Rendering.SelectListGroup' requires a primary key to be defined 实体类型“列表<string> ' 需要定义主键</string> - The entity type 'List<string>' requires a primary key to be defined Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll 中发生“System.InvalidOperationException” - 'System.InvalidOperationException' occurred in Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll 无法修复&#39;IdentityUserLogin <string> 需要主键&#39;错误 - Can't fix 'IdentityUserLogin<string> requires primary key' error 实体类型需要定义一个主键 - The entity type requires a primary key to be defined 实体类型“AspNetUserLogins”需要定义主键? - The entity type 'AspNetUserLogins' requires a primary key to be defined? 实体类型需要定义一个主键 - Entity Type requires a primary key to be defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM