Skip to content

Instantly share code, notes, and snippets.

@gabrieljoelc
Created November 7, 2013 03:42
Show Gist options
  • Save gabrieljoelc/7348614 to your computer and use it in GitHub Desktop.
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…
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; }
}
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