实体框架代码先0到1映射

本文关键字:映射 框架 代码 实体 | 更新日期: 2023-09-27 17:50:30

我想创建这2个模型的映射,我如何在代码优先中做到这一点?

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可以是PaymentBankPaymentCheque类型。我在试着模拟这样的场景。如果可能的话,我希望可以继承这个,比如:

public class PaymentCheque : Payment
{
    public int RoutingNumber {get; set;}
}   

实体框架代码先0到1映射

您可以查看以下三篇文章,它们专注于在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

你真的试过吗?或者搜索/谷歌一下?

见: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