Code First で 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"));
すべてが正常に機能しているようで、3 つのテーブルが作成され、シード時に期待するデータが入力されています。唯一の問題は、TPH を使用する場合と同様に、「セクション」テーブルで生成された「ディスクリミネーター」フィールドをまだ取得していることです。それがなぜなのか、どうすればそれを取り除くことができるのでしょうか?
シンプルな Animal/Cat/Dog タイプのクラスを使用して問題を再現しようとしましたが、(面倒なことに) うまくいきました!