Created
November 7, 2013 03:42
-
-
Save gabrieljoelc/7348614 to your computer and use it in GitHub Desktop.
Entity Framework 6 inheritance strategy defaults.
Table per Hierarchy (TPH) - one table for all types with type discriminator column
Table per Concrete Type (TPC) - one table per concrete type with common properties copied in each table From http://weblogs.asp.net/manavi/archive/2010/12/24/inheritance-mapping-strategies-with-entity-framework-cod…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class BillingDetail | |
{ | |
public int BillingDetailId { get; set; } | |
public string Owner { get; set; } | |
public string Number { get; set; } | |
} | |
public class BankAccount : BillingDetail | |
{ | |
public string BankName { get; set; } | |
public string Swift { get; set; } | |
} | |
public class CreditCard : BillingDetail | |
{ | |
public int CardType { get; set; } | |
public string ExpiryMonth { get; set; } | |
public string ExpiryYear { get; set; } | |
} | |
public class InheritanceMappingContext : DbContext | |
{ | |
public DbSet<BankAccount> BankAccounts { get; set; } | |
public DbSet<CreditCard> CreditCards { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class BillingDetail | |
{ | |
public int BillingDetailId { get; set; } | |
public string Owner { get; set; } | |
public string Number { get; set; } | |
} | |
public class BankAccount : BillingDetail | |
{ | |
public string BankName { get; set; } | |
public string Swift { get; set; } | |
} | |
public class CreditCard : BillingDetail | |
{ | |
public int CardType { get; set; } | |
public string ExpiryMonth { get; set; } | |
public string ExpiryYear { get; set; } | |
} | |
public class InheritanceMappingContext : DbContext | |
{ | |
public DbSet<BillingDetail> BillingDetails { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment