1

Entity Framework 5 を破棄します! Web から解決策を見つけるために 2 日間費やしましたが、何も見つかりませんでした。

入力IDFondazioneを2620として、テーブルArtworksとEndValiditiesから単純な左結合を試みました

var query = from art in db.Artworks
  join endVal in db.EndValidities.DefaultIfEmpty() 
  on art.ID_Dtsl equals endVal.IDdtsl 
  where art.ID_Cdgs == IDFondazione
  select new SchedaOpera()
  {
    Cdscheda = art.Cdscheda,
    Confirmed = art.FGconfermata,
    DSimmagine = art.DSimmgine,
    Dtsf = art.Dtsf,
    Dtsi = art.Dtsi,
    Dtsl = endVal != null ? endVal.Dtsl : "",
    Iscr = art.Iscr,
    Misa = art.Misa,
    Ldcn = art.Ldcn,
    Ldcs = art.Ldcs,
    Misd = art.Misd,
    Misl = art.Misl,
    Misn = art.Misn,
    Misp = art.Misp,
    Miss = art.Miss,
    Pvcc = art.Pvcc,
    Pvcp = art.Pvcp,
    Sgtt = art.Sgtt
  };

素晴らしいエンティティ フレームワークは、引き続き生成します。

SELECT [Extent1].[ID_Dtsl] AS [ID_Dtsl], [Extent1].[CDscheda] AS [CDscheda], 
[Extent1].[FGconfermata] AS [FGconfermata], 
[Extent1].[DSimmagine] AS [DSimmagine], 
[Extent1].[DS_DTSF] AS [DS_DTSF], 
[Extent1].[DS_DTSI] AS [DS_DTSI], 
CASE WHEN (cast(1 as bit) <> cast(0 as bit)) THEN [Extent2].[DSdtsl] ELSE N'_' END AS [C1], 
[Extent1].[DS_ISCR] AS [DS_ISCR], 
[Extent1].[NR_MISA] AS [NR_MISA], 
[Extent1].[DS_LDCN] AS [DS_LDCN], 
[Extent1].[DS_LDCS] AS [DS_LDCS], 
[Extent1].[NR_MISD] AS [NR_MISD], 
[Extent1].[NR_MISL] AS [NR_MISL], 
[Extent1].[NR_MISN] AS [NR_MISN], 
[Extent1].[NR_MISP] AS [NR_MISP], 
[Extent1].[NR_MISS] AS [NR_MISS], 
[Extent1].[FGpubblicata] AS [FGpubblicata], 
[Extent1].[DS_PVCC] AS [DS_PVCC], 
[Extent1].[DS_PVCP] AS [DS_PVCP], 
[Extent1].[DS_SGTT] AS [DS_SGTT]
FROM  [dbo].[TPD_OPERE] AS [Extent1]
INNER JOIN [dbo].[TSA_DTSL] AS [Extent2] ON [Extent1].[ID_Dtsl] = [Extent2].[IDdtsl]
WHERE [Extent1].[CD_CDGS] = '2620'
4

4 に答える 4

2

DefaultIfEmptyEntity Framework では、ナビゲーション プロパティでのみ機能します。それ以外の場合はGroupJoin、を使用する必要があります。これは、包括的な構文でjoin...によって実現されますinto。詳細については、この優れた投稿を参照してください。

したがって、クエリは次のようになります (GroupJoin):

from art in db.Artworks
join endVal in db.EndValidities on art.ID_Dtsl equals endVal.IDdtsl
into g // can be any name
where art.ID_Cdgs == IDFondazione
...

違いは、オブジェクトを選択するステートメントと、オブジェクトごとのオブジェクトartのコレクションです。したがって、プロパティはonで、値のコレクションを生成する必要があります。コレクションは、外部結合を表す空 (要素なし) にすることができます。endValartDtslSelectendVal.DtslDtsl

または、ナビゲーション プロパティがある場合Artwork.EndValidities:

from art in db.Artworks
from endVal in art.EndValidities.DefaultIfEmpty() 
...
于 2012-09-19T22:29:06.950 に答える
1

linqpad でテストされた私のデモでは、以下のように 2 つのテーブルを外部結合のままにすることができます。

var resultAcctInfo = (
                from p in Focus_Person
                where String.Compare(p.Login, "yourname", true) == 0 && (p.AcctStatusID == 1 || p.AcctStatusID == 2)
                join an in Focus_SecurityAnswer on p.PersonID equals an.PersonID into G
                //from g in G //You can uncommented this line to check the difference.
                join q in Focus_SecurityQuestion on G.FirstOrDefault().QuestionID equals q.QuestionID into Q  //left join question table
                //from q in Q                   
                select new
                {
                    Person = p,
                    Answer = G.FirstOrDefault(),                        
                    //Question = q,
                });
resultAcctInfo.Dump();
于 2013-06-27T05:45:13.877 に答える
0
from art in db.Artworks
join endValidities in db.EndValidities
on art.ID_Dtsl equals endValidities .IDdtsl into ev
where art.ID_Cdgs == IDFondazione

from endVal in ev.DefaultIfEmpty()
select new SchedaOpera()
     {
          Cdscheda = art.Cdscheda,
          Confirmed = art.FGconfermata,
          DSimmagine = art.DSimmgine,
          Dtsf = art.Dtsf,
          Dtsi = art.Dtsi,
          Dtsl = endVal.Dtsl ?? string.Empty,
          Iscr = art.Iscr,
          Misa = art.Misa,
          Ldcn = art.Ldcn,
          Ldcs = art.Ldcs,
          Misd = art.Misd,
          Misl = art.Misl,
          Misn = art.Misn,
          Misp = art.Misp,
          Miss = art.Miss,
          Pvcc = art.Pvcc,
          Pvcp = art.Pvcp,
          Sgtt = art.Sgtt
     };
于 2012-09-19T13:27:13.310 に答える
0

私はこの作業コードを持っています:-

  var res = from et in db.entity_test join en in db.entity_new on et.id equals en.id into ps from en in ps.DefaultIfEmpty() select new {Name = et.name,Email=en.email };

    GridView1.DataSource = res;
    GridView1.DataBind();
于 2013-08-08T13:44:42.440 に答える