【发布时间】:2015-02-27 17:15:50
【问题描述】:
我正在尝试使用以下两个类设置外键。 我想使用 pAcqType 作为枚举并将类型的名称存储在另一个表中。我应该如何设置我的课程来做到这一点?
public class Property
{
[Key]
public int pID { get; set; }
public string pAddress { get; set; }
public string pCounty { get; set; }
public string pCity { get; set; }
public string pState { get; set; }
public string pzip { get; set; }
public virtual PropertyAcquisitionType pAcqType { get; set; } <-- foreign key
}
public class PropertyAcquisitionType
{
[Key]
public int patID { get; set; }
public string patName { get; set; }
}
更新
丹让我思考。我尝试了以下方法,它似乎已经解决了。 它像我想要的那样在桌子上设置了外键。它甚至没有要求另一张桌子上的倒数。
public int? pAcqType { get; set; }
[ForeignKey("pAcqType")]
public PropertyAcquisitionType patID { get; set; }
【问题讨论】:
标签: asp.net entity-framework ef-code-first