Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Code First 0 to 1 mapping

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;}
}   
like image 719
Shawn Mclean Avatar asked Apr 18 '11 05:04

Shawn Mclean


2 Answers

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

like image 197
Kamyar Avatar answered Oct 19 '22 21:10

Kamyar


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

like image 32
Euphoric Avatar answered Oct 19 '22 20:10

Euphoric