真的會很感激一點關於如何在我自己的MVC5自定義類中使用ApplicationUser的指導。MVC5實體框架代碼第一次錯誤創建數據庫當使用ApplicationUser
簡單模型,使用腳手架創建控制器和視圖,從Internet應用程序模板的默認ApplicationUser(IdentityUser)sm DbContext。我想使用ApplicationUser來爲交易添加當時登錄的人員的詳細信息。
我得到兩個數據庫錯誤之一,當實體框架試圖DropAndRecreateAlways
一是我的課:
public class Example
{
public int ID { get; set; }
[Required]
public string Description { get; set; }
[Required]
public double Amount { get; set; }
[Required]
public virtual ApplicationUser CreatedBy {get; set;}
[Required]
public virtual ApplicationUser ModifiedBy { get; set; }
}
錯誤,我得到當實體框架試圖創建數據庫中:
{「模型生成過程中檢測到一個或多個驗證錯誤:\ r \ n \ r \ nMvcApplication1.Models.IdentityUserLogin :: EntityType'IdentityUserLogin'has no ke y定義。定義此EntityType的密鑰。\ r \ nMvcApplication1.Models.IdentityUserRole :: EntityType'IdentityUserRole'沒有定義密鑰。 \ r \ nIdentityUserLogins:EntityType:EntitySet'IdentityUserLogin'基於'IdentityUserLogin'類型,沒有定義鍵。\ r \ nIdentityUserRoles:EntityType:EntitySet'IdentityUserRoles'基於'IdentityUserRole'類型。有沒有鍵定義。\ r \ n「}
參照完整性由於梯級上刪除(我可以覆蓋的DbContext刪除級聯刪除)
什麼是實現這一目標的最佳途徑?任何指導將不勝感激。
你可以提供IdentityUserLogin,IdentityUserRole和DbContext的代碼嗎? – bdparrish
我認爲這是一個上下文相關的問題。我猜你有兩個上下文。嘗試合併兩者。 –
MVC5默認的Internet應用程序創建ApplicationUser,它繼承自包含IdentityUserLogin和IdentityUserRole的IdentityUser,這些對我的項目不可見。 –