2012-07-24 114 views
3

我有一個兩個表,我需要連接和選擇值,連接需要離開外部連接。我試圖使用LINQ到SQL,但得到0,而不是實際值LINQ到SQL外部左連接與多個連接條件

引用表:

refType varchar(250), 
description varchar(250) 

presentationsType(我的另一個表)

id int 
refType varchar(250), 
OtherFundings varchar(250) 

查詢我現在用的就是

string organization = (string)Session["organization"]; 
int FiscalYear = Int32.Parse((string)Session["fiscalyear"]); 
string ReportingPeriod = (string)Session["reportingperiod"]; 

var presentationType = from pt in OCHART.References 
         join rf in OCHART.OCHART_PresentationTypes on pt.RefType equals rf.RefType into prt          
         from x in prt.Where(prt2 => prt2.OrganizationName.Equals(organization) && prt2.ReportingPeriod.Equals(ReportingPeriod) && prt2.FiscalYear == FiscalYear).DefaultIfEmpty() 
         where pt.RefType.Equals("09-10.1b")           
         orderby pt.RefOrder ascending 
         select new { 
           refType = pt.RefType, 
           refName = pt.Description, 
           otherFundings = (x.Fundings == null ? 0 : x.Fundings), 
           id = (x.id == null ? 0 : x.id) 
         }; 

但是我得到id = 0和otherFunding = 0,儘管在第二個表中有適當的值。我真的不確定我做錯了什麼。

希望能有所幫助。

謝謝。

+0

我相信你可以標記你自己的刪除問題,因爲它沒有任何好處。 – Adam 2012-07-24 14:58:08

回答

0

我恨它,當我創建打破我的頭和比長的時間後一個問題找到我自己只是右後它的解決方案。

請打消這個問題,我的問題是不連接的加入適當的領域。

對不起。

+0

在這種情況下,也許分享你自己的答案。它可能會幫助別人:) – Riaan 2012-07-24 14:58:29