繁体   English   中英

当包括类型ApplicationUser的属性时,“为此实体类型定义键。”

[英]“Define the key for this EntityType.” when including attribute of type ApplicationUser

我正在编写C#/ ASP.NET MVC5 Web应用程序,尝试进行新迁移时遇到以下错误

ToTheMoon.DAL.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
ToTheMoon.DAL.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.

我在一个模型中包含了ApplicationUser类型的property(?)。 我相信这是造成它的原因:

public ApplicationUser Requester { get; set; }

我很清楚这样一个事实,总的来说,我应该使用[Key]批注明确地将某项标记为键,但是我不认为这适用,因为错误消息描述的类是MVC5的“包含的电池”的一部分登录系统。

我已经看到有关此问题的信息,这是由于错误地重写一种方法(不记得它现在是一种方法)引起的,但是我没有这样做,因此我在网上发现的所有其他问题对我来说都是无用的。

一切都赞赏。

编辑:这是我的上下文,很裸露。

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext() : base("DefaultConnection") { }
}

从问题中的评论中:

似乎添加了ApplicationUser Requester属性的实体是在不同的上下文中定义的。 因为上下文是在另一个上下文中,所以上下文对所有Identity实体的配置一无所知,因为这是由IdentityDbContext.OnModelCreating方法设置的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM