1
我在Code First使用EF 4.3時遇到了TPT問題。我有以下類: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; }
}
映射使用流利的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一樣。任何想法,爲什麼會這樣,我如何擺脫它?
我試圖複製使用簡單的動物/貓/狗類型的問題,(煩人)工作正常!
您是否首次使用TPH並讓遷移將其更改爲TPT? – 2012-08-17 07:11:34
我在實體框架5.0.0中有這個相同的問題。就我而言,它是使用TPT的多級繼承。你解決了這個問題嗎? – 2013-02-18 22:55:48
我有類似的問題。我有一個抽象基類,許多派生類中的一個有一個鑑別器,我試圖擺脫目前爲止沒有運氣。 – Jonny 2016-10-20 07:51:59