I have the following class hierarchy
public class A
{
public int Id { get; set; }
public virtual IColection<B> Items {get; set; }
}
public abstract class B
{
public int Id {get; set; }
public A Parent {get; set; }
}
public class C : B
{
public String Name {get; set; }
}
I'm trying to use Table per concrete type hierarchy mapping and the following code to DataContext
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<C>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("C_Table");
});
}
Entity Framework still creates two tables. One for class B that includes Id and A_Id field for foreign key. Second one for C with all fields except reference to A.
Is it possible to configure EF not to create table for B? I want to have separate table for each derived class but without common table.
unioning multiple child tables. This is a problem anyway because now you have to make sure that each derived class has its own PK range so the PKs in B are unique. - Gert Arnold