【发布时间】:2015-02-24 05:22:06
【问题描述】:
我有两个模型,一个 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 吗?在属性和外键属性中。
标签: asp.net-mvc entity-framework ef-code-first code-first