Entity Framework Code First 0 到 1 映射
我想创建这两个模型的地图,如何在代码优先中执行此操作?
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
类型。我正在尝试遵循类似的场景 这个。如果可能的话,我希望能够继承它,例如:
public class PaymentCheque : Payment
{
public int RoutingNumber {get; set;}
}
I want to create a map of these 2 models, how do I do this in code-first?
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
can be either of type PaymentBank
or PaymentCheque
. I'm trying to follow a scenario like this. I'd love if I could do inheritance of this if possible, such as:
public class PaymentCheque : Payment
{
public int RoutingNumber {get; set;}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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
You can check out the following three articles which focus on implementing inheritance in 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
你真的尝试过吗?或者搜索/谷歌搜索它?
请参阅:
Did you actualy try it? Or search/google for it?
see: 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