C# EF 4.3-使用TPT仍然在基础上生成鉴别器字段

C# EF 4.3-使用TPT仍然在基础上生成鉴别器字段,c#,ef-code-first,entity-framework-4.3,C#,Ef Code First,Entity Framework 4.3,我对首先使用EF 4.3和代码的TPT有问题。我有以下课程: public class Section { public int Id { get; set; } .... public int SurveyId { get; set; } public virtual Survey Survey { get; set; } } public class IntroductionSection : Section { public string Exampl

我对首先使用EF 4.3和代码的TPT有问题。我有以下课程:

public class Section
{
    public int Id { get; set; }

....

    public int SurveyId { get; set; }
    public virtual Survey Survey { get; set; }
}

public class IntroductionSection : Section
{
    public string ExampleText { get; set; }
}

public class QuestionSection : Section
{
    public int ExampleNumber { get; set; }
}
使用Fluent API映射如下:

modelBuilder.Entity<Section>().Map(m => m.ToTable("Section"));
modelBuilder.Entity<Section>().HasRequired(m => m.Survey).WithMany(s => s.Sections).HasForeignKey(t => t.SurveyId);

modelBuilder.Entity<IntroductionSection>().Map(m => m.ToTable("Introduction"));
modelBuilder.Entity<QuestionSection>().Map(m => m.ToTable("Question"));
所有这些似乎都工作正常,三个表被创建并填充了我在播种时期望的数据——唯一的问题是我仍然在“Section”表中生成一个“Discriminator”字段,就像我使用TPH一样。你知道为什么会这样吗?我怎样才能摆脱它


我尝试使用简单的动物/猫/狗类型的类来复制这个问题,这很好

我刚刚解决了我的问题。在我的例子中,我的模型有一个抽象基类。从基类继承的所有模型

我一直在使用TPT,但数据库中突然出现了一个鉴别器。我花了一些时间试图摆脱鉴别器,最后注意到我有一个视图模型,它是从带有鉴别器的模型派生出来的


我在视图模型类中添加了[NotMapped]属性,鉴别器不再存在。

您是第一次使用TPH并让迁移将其更改为TPT吗?在Entity Framework 5.0.0中,我也遇到了同样的问题。在我的例子中,它是使用TPT的多层次继承。你解决这个问题了吗?我有一个类似的问题。我有一个抽象基类,许多派生类中的一个有一个鉴别器,我正试图摆脱它,但到目前为止运气都不好。