簡體   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