我有兩個模型,其中一個ApplicationUser
它擁有系統中的所有用戶,並且我有一個引用模型,它將容納所有Quotations
。現在我想在Quotations
裏面存儲兩個映射到ApplicationUser
。這樣我就可以映射到已創建的用戶以及已取消的用戶。我的模型看起來像這樣實體框架代碼首先映射相同的實體兩次用於不同的目的
public class Quotation
{
public int QuotationID { get; set; }
public DateTime QuotationDate { get; set; }
public DateTime QuotationCancelDate { get; set; }
public int ApplicationUserID { get; set; }
public virtual ApplicationUser CreatedUser { get; set; }
[ForeignKey("ApplicationUserID")]
public ApplicationUser CancelledUser { get; set; }
}
但是,這會引發錯誤
Quotation_CancelledUser_Target_Quotation_CancelledUser_Source: : The types of all properties in the Dependent Role of a referential constraint must be the same as the corresponding property types in the Principal Role. The type of property 'ApplicationUserID' on entity 'Quotation' does not match the type of property 'Id' on entity 'ApplicationUser' in the referential constraint 'Quotation_CancelledUser'.
所以我想,我採用的方法是錯誤的。任何人都可以指出實現這一目標的正確方法嗎?
嘗試將ApplicationUserID更改爲ApplicationUserId?在屬性和外鍵屬性中。 – 2015-02-24 05:26:52