Table Per Concrete Type (TPC) Inheritance in Entity Framework 6 (EF6)

后端 未结 2 2184
自闭症患者
自闭症患者 2021-02-20 05:39

In an effort to avoid the use of Table Per Hierarchy (TPH) I have been looking at examples of how best to implement Table-Per-Concrete Class (TPC) inheritance in my database mod

2条回答
  •  情话喂你
    2021-02-20 06:34

    I use mapping classes, but never-mind. I solve it like this:

    public class PersonMap : EntityTypeConfiguration
    {
        public PersonMap()
        {
            Map(m => { m.ToTable("Person"); m.MapInheritedProperties(); });
    
            HasKey(p => p.Id);
            Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
        }
    
    }
    

    Remember - base class must be abstract.

提交回复
热议问题