我正在按照建议编写代码,
public class A
{
public int id {get;set;}
public string Astring {get;set;}
}
public class B : A
{
public string Bstring {get;set;}
}
builder.Entity<A>().MapHierarchy( u=> new { ... }).ToTable("A");
builder.Entity<B>().MapHierarchy( u=> new { ... }).ToTable("B");
... = 我有所有提到的属性和 u.Id 。
当我使用模型构建器时,我也有两者的DbSet<A> A {get;set;}
和DbSet<B> B {get;set;}
和ObjectSet
属性
builder.Entity<A>
builder.Entity<B>
这导致创建表 A 时带有一个鉴别器列和 Id、Astring、Bstring。这是默认的 TPH 映射,不知道为什么会这样。谢谢