2013-01-11 17 views
1

我從表中通過應用聯接兩個表中獲取數據,但我得到這個錯誤:錯誤連接子句中的一個表達式的類型不正確。類型推斷呼叫失敗「加入」

Error 40 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'. C:\Documents and Settings\Ashir\My Documents\OpenLearningSolutions08-01-2013\OpenLearningSolutions\purchase.aspx.cs 70 21 C:\...\OpenLearningSolutions\ 

這裏是我的代碼:

OLSContainer ols = new OLSContainer(); 
     var reSet = from l in ols.LEVEL_COURSE 
        join lp in ols.PACKAGES 
        on new { l.course_ID, l.levelID } equals new { lp.course_ID, lp.level_ID } 
        select l; 

雖然所有的四列都是int nullabe類型的,但我得到這個錯誤。請幫助我。

回答

1

我解決了從表中選擇數據這樣我的問題:

OLSContainer ols = new OLSContainer(); 
     var reSet = (from l in ols.LEVEL_COURSE 
        from p in ols.PACKAGES 
        where l.course_ID == p.course_ID && l.levelID == p.level_ID && l.course_ID==courseID 
        select new { l.levelID, l.levelName }).Distinct(); 
1

在你LINQ表達,所述成員的名稱是不同的,所以類型最終被不同的,所以C#不能找出兩者之間的常見的類型。

試試這個。

OLSContainer ols = new OLSContainer(); 
var reSet = from l in ols.LEVEL_COURSE 
       join lp in ols.PACKAGES 
       on new { l.course_ID, l.levelID } equals new { course_ID = lp.course_ID, levelID = lp.level_ID } 
       select l; 
+0

什麼是第二個新表達式中的course_ID和levelID? –

+0

這是從左側的成員名稱中加入表達 –

+0

我解決我的問題,通過選擇數據形式的表是這樣的: –

0

如果你是比較中斷?例如,int可以將.Value附加到可爲空的屬性。

+0

感謝,但我解決它自己,給自己的答案以及.. :) –

相關問題