简体   繁体   English

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

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

I'm writing C#/ASP.NET MVC5 web application, and I'm hitting the following errors when I try to do a new migration 我正在编写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.

I have included a property(?) of type ApplicationUser in one of my models. 我在一个模型中包含了ApplicationUser类型的property(?)。 I believe that this is what's causing it: 我相信这是造成它的原因:

public ApplicationUser Requester { get; set; }

I am well aware of the fact that—in general—I should explicitly mark something as a key with the [Key] annotation, but I don't believe this applies as the error messages are describing classes that are part of MVC5's 'batteries included' login system. 我很清楚这样一个事实,总的来说,我应该使用[Key]批注明确地将某项标记为键,但是我不认为这适用,因为错误消息描述的类是MVC5的“包含的电池”的一部分登录系统。

I have seen something about this being caused by incorrectly overriding a method (can't remember what one it is now), but I'm not doing that, so all other questions that I've found online are useless to me. 我已经看到有关此问题的信息,这是由于错误地重写一种方法(不记得它现在是一种方法)引起的,但是我没有这样做,因此我在网上发现的所有其他问题对我来说都是无用的。

Anything is appreciated. 一切都赞赏。

EDIT: Here's my context, it's pretty bare. 编辑:这是我的上下文,很裸露。

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

From the comments in the Question: 从问题中的评论中:

It appears the entity that added the ApplicationUser Requester property is defined in a different context. 似乎添加了ApplicationUser Requester属性的实体是在不同的上下文中定义的。 Because it is in a different context that context knows nothing about the configurations for all of the Identity entities, since that is set up by the IdentityDbContext.OnModelCreating method. 因为上下文是在另一个上下文中,所以上下文对所有Identity实体的配置一无所知,因为这是由IdentityDbContext.OnModelCreating方法设置的。

暂无
暂无

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

相关问题 EF 5.0 Fluent映射:“ EntityType&#39;{ClassMap}&#39;”未定义键。 定义此EntityType的密钥。” - EF 5.0 Fluent mapping: “EntityType '{ClassMap}' has no key defined. Define the key for this EntityType.” EntityType&#39;&#39;没有定义键。 定义此EntityType的键。 -C#Web API实体框架 - EntityType ' ' has no key defined. Define the key for this EntityType. - C# Web API Entity Framework 实体框架4.3.1 - &gt; 5.0异常:“EntityType没有定义键。 定义此EntityType的键。“ - Entity Framework 4.3.1 -> 5.0 Exception: “EntityType has no key defined. Define the key for this EntityType.” EntityType“帖子”没有定义键。 定义此EntityType的键 - EntityType 'posts' has no key defined. Define the key for this EntityType EntityType&#39;MyProfile&#39;没有定义键。 定义此EntityType的键 - EntityType 'MyProfile' has no key defined. Define the key for this EntityType EntityType没有定义键。 定义此EntityType的键 - EntityType has no key defined. Define the key for this EntityType EntityType X没有定义键。 定义此EntityType的键 - EntityType X has no key defined. Define the key for this EntityType 代码优先:EntityType &#39;xxxx&#39; 没有定义键。 添加 n 对 n 关系时定义此 EntityType 的键 - Code first: EntityType 'xxxx' has no key defined. Define the key for this EntityType when adding n-to-n relationship EntityType &#39;Worker&#39; 没有定义键。 定义此 EntityType 的键 - EntityType 'Worker' has no key defined. Define the key for this EntityType 模型验证错误:EntityType 未定义键。 定义此 EntityType 的键 - Model validation error: EntityType has no key defined. Define the key for this EntityType
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM