2009-08-11 13 views
2

私はかなり複雑なLINQクエリを持っている:"サブクエリがEXISTSで導入されていない場合、選択リストに指定できる式は1つだけです。

var q = from eiods in LinqUtils.GetTable<EIOfficialDesignee>() 
     let eiodent = eiods.Entity 
     join tel in LinqUtils.GetTable<EntityTelephone>() 
     on new { EntityID = eiodent.ID, TelephoneType = EntityTelephone.TTelephone.Office } equals new { tel.EntityID, tel.TelephoneType } 
     into Tel 
     let Tel1 = Tel.FirstOrDefault() 
     join fax in LinqUtils.GetTable<EntityTelephone>() 
     on new { EntityID = eiodent.ID, TelephoneType = EntityTelephone.TTelephone.Fax } equals new { fax.EntityID, fax.TelephoneType } 
     into Fax 
     let Fax1 = Fax.FirstOrDefault() 
     join cell in LinqUtils.GetTable<EntityTelephone>().DefaultIfEmpty() 
     on new { EntityID = eiodent.ID, TelephoneType = EntityTelephone.TTelephone.Mobile } equals new { cell.EntityID, cell.TelephoneType } 
     into Mobile 
     let Mobile1 = Mobile.FirstOrDefault() 
     where eiods.ID == CurrentEIPatient.EIOfficialDesigneeID 
     select new { 
      ID = eiods.ID, 
      EIODName = eiodent.FormattedName, 
      Phone = Tel1 != null ? Tel1.FormattedNumber : "", 
      Fax = Fax1 != null ? Fax1.FormattedNumber : "", 
      Cellphone = Mobile1 != null ? Mobile1.FormattedNumber : "", 
     }; 

このクエリは私にSQLエラーを返して:

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS 
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS 
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS 

はい、三重に。これは、クエリの問題が3回、すなわち3種類の電話番号で繰り返されているという明白な指標です。

SQLサーバーのドキュメントによると、これは不正な形式のクエリに由来します。しかし、これは天国のためのLinqです!どのようにクエリの不正な形式になる可能性がありますか?メインの答えは別に

、私も...私のクエリの最適化について

おかげであなたが持つかもしれないコメントをいただければと思います!

答えて

2

それを自分で解決しました。ここには他の誰かの利益のためにあります。 FormattedNumberプロパティはEntityTelephoneオブジェクトのNumberExtension特性に基づいて計算フィールドであること

Phone = Tel1 != null ? Tel1.FormattedNumber : "", 
Fax = Fax1 != null ? Fax1.FormattedNumber : "", 
Cellphone = Mobile1 != null ? Mobile1.FormattedNumber : "", 

悪魔は、特に端部でSELECT句です。 FormattedNumberNumberに置き換えると、すべて正常に動作します。

この問題を解決する最適な方法は、hereです。

関連する問題

 関連する問題