我想创建这两个模型的地图,我该如何在代码优先实现?
public class Payment
{
public int PaymentId { get; set; }
}
public class PaymentBank
{
public int PaymentId { get; set; }
}
public class PaymentCheque
{
public int PaymentId { get; set; }
}
Payment
可以是PaymentBank
或PaymentCheque
类型。我正在尝试按照this之类的方案。如果可能的话,如果我可以继承这个,我会很高兴,例如:
public class PaymentCheque : Payment
{
public int RoutingNumber {get; set;}
}
答案 0 :(得分:2)
您可以查看以下三篇专注于在Entity Framework Code-First中实现继承的文章:
http://weblogs.asp.net/manavi/archive/2010/12/24/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tph.aspx
http://weblogs.asp.net/manavi/archive/2010/12/28/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-2-table-per-type-tpt.aspx
http://weblogs.asp.net/manavi/archive/2011/01/03/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-3-table-per-concrete-type-tpc-and-choosing-strategy-guidelines.aspx
答案 1 :(得分:1)