現在、EF4.1にいくつか問題があります。 SQLの生成は、私のクラスに基づいて生成されると予想されるものと一致していないようです。私は(私は問題を抱えてのように見える。これは大きなコレクションのちょうど小さく設定されている、しかし、これは)次のクラスを...持ってエンティティフレームワーク4.1ゴースト列
public class CustomEntityContext : DbContext
{
public CustomEntityContext()
:base(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString) {}
public DbSet<Person> People { get; set; }
public DbSet<Occurrence> Occurrences { get; set; }
public DbSet<OccurrenceSecurity> OccurrenceSecurities { get; set; }
}
[DataContract(IsReference = true)]
[Table("Occurrence")]
public class Occurrence
{
[DataMember] public int ID { get; set; }
[DataMember] public string Number { get; set; }
[DataMember] public bool? IsMOR { get; set; }
[DataMember] public bool? IsConfidential { get; set; }
[DataMember] public int? IncidentID { get; set; }
[DataMember] public bool? CanPublish { get; set; }
[DataMember] public bool? IsFeedbackRequired { get; set; }
[DataMember] public bool? IsRegulatorReport { get; set; }
[DataMember] public DateTime? RecordedDate { get; set; }
[DataMember] public DateTime? ReportedDate { get; set; }
[DataMember] public int? ReportTypeID { get; set; }
[DataMember] public bool? IsMain { get; set; }
[DataMember] public bool? IsRejected { get; set; }
[DataMember] public string Title { get; set; }
[DataMember] public byte[] Version { get; set; }
[DataMember] public string ReportDataXml { get; set; }
[DataMember] public int? LocationID { get; set; }
[DataMember, ForeignKey("RecordedByPersonID")] public Person Recorder { get; set; }
[DataMember, ForeignKey("ReportedByPersonID")] public Person Reporter { get; set; }
}
[DataContract(IsReference = true)]
[Table("OccurrenceSecurity")]
public class OccurrenceSecurity
{
[DataMember, Key, Column("PersonID", Order = 0)] public int PersonID { get; set; }
[DataMember, ForeignKey("PersonID")] public Person Person { get; set; }
[DataMember, Key, Column("OccurrenceID", Order = 1)] public int OccurrenceID { get; set;
[DataMember, ForeignKey("OccurrenceID")] public Occurrence Occurrence { get; set; }
}
[DataContract(IsReference = true)]
[Table("Person")]
public class Person
{
[DataMember] public int ID { get; set; }
[DataMember] public string FullName { get; set; }
//[DataMember] public Occurrence[] RecordedOccurrences { get; set; }
//[DataMember] public Occurrence[] ReportedOccurrences { get; set; }
//[DataMember] public OccurrenceSecurity[] OccurrenceSecurities { set; get; }
}
私は含める方法で、OccurrenceSecuritiesを求めます私は出現と人の両方を含めるように頼みます。その後、次のように生成されたSQLがある...
SELECT
[Extent1].[PersonID] AS [PersonID],
[Extent1].[OccurrenceID] AS [OccurrenceID],
[Extent2].[ID] AS [ID],
[Extent2].[FullName] AS [FullName],
[Extent3].[ID] AS [ID1],
[Extent3].[Number] AS [Number],
[Extent3].[IsMOR] AS [IsMOR],
[Extent3].[IsConfidential] AS [IsConfidential],
[Extent3].[IncidentID] AS [IncidentID],
[Extent3].[CanPublish] AS [CanPublish],
[Extent3].[IsFeedbackRequired] AS [IsFeedbackRequired],
[Extent3].[IsRegulatorReport] AS [IsRegulatorReport],
[Extent3].[RecordedByPersonID] AS [RecordedByPersonID],
[Extent3].[RecordedDate] AS [RecordedDate],
[Extent3].[ReportedByPersonID] AS [ReportedByPersonID],
[Extent3].[ReportedDate] AS [ReportedDate],
[Extent3].[ReportTypeID] AS [ReportTypeID],
[Extent3].[IsMain] AS [IsMain],
[Extent3].[IsRejected] AS [IsRejected],
[Extent3].[Title] AS [Title],
[Extent3].[Version] AS [Version],
[Extent3].[ReportDataXml] AS [ReportDataXml],
[Extent3].[LocationID] AS [LocationID],
[Extent3].[Person_ID] AS [Person_ID], -- Where does this come from?
[Extent3].[Person_ID1] AS [Person_ID1] -- Where does this come from?
FROM [dbo].[OccurrenceSecurity] AS [Extent1]
INNER JOIN [dbo].[Person] AS [Extent2] ON [Extent1].[PersonID] = [Extent2].[ID]
LEFT OUTER JOIN [dbo].[Occurrence] AS [Extent3] ON [Extent1].[OccurrenceID] = [Extent3].[ID]
あなたが見ることができるように、2列はPERSON_IDとPerson_ID1を選択している選択ブロックの最後にあります。これらは、私の基になるテーブルまたは私のオブジェクトには存在しません。
どこから来たのか、なぜそこにいるのか誰にでも分かりますか?
また、これは多対多の関係であることを認識していますが、OccurrenceSecuritiesテーブル/クラスはさらにデータを保持するために拡張されます。
おかげで、含める方法と デビッド
DbContextクラスのOnModelCreatingメソッドを使用してモデルを構成しようとしましたが、私は、エンティティの各属性から構成をコピーし、それらの属性を削除しました。そして、これらの2つの追加の列なしでSQLクエリが生成されます。 –