Table-per-Hierarchy inheritance in Entity Framework 7

.net c# entity-framework entity-framework-core inheritance

Question

I'm using Entity Framework beta 8 and Code First to work with SQLite Database.

I need to have TPH inheritance, but by default it uses TPT inheritance.

Here is a part of my code:

 public abstract partial class Amenity
 {
    [Key]
    public int AmenityId { get; set; }
    public string AmenityName { get; set; }
 }

 public class AmenityCountable : Amenity
 {
    public int AmenityMinValue { get; set; }
    public int AmenityMaxValue { get; set; }
    public string AmenityTypeName { get; set; }
 }

 public class AmenityOptionable : Amenity
 {
    public bool CanHaveMultipleValues { get; set; }
 }

 public class KMContext : DbContext
 {
    public virtual DbSet<Amenity> Amenities { get; set; }
    public virtual DbSet<AmenityCountable> AmenityCountable { get; set; }
    public virtual DbSet<AmenityOptionable> AmenityOptionable { get; set; }
 }

How do I modify it so that it uses TPH inheritance?

Popular Answer

TPH will be available in the RC release

see github entityframework about TPH



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why