2014-10-09 114 views
0

有人能幫助我,請將此SQL代碼轉換爲LINQ。將SQL代碼轉換爲LINQ(內部連接查詢)

SQL查詢

select distinct coursecode 
from UnitSet_Unit 
where UnitCode in ('FDFFSACA' ,'FDFFSCFSAA', 'FDFOPTHCP3A ') 
and CourseCode in (Select distinct coursecode 
        from Trainee_course 
        where TraineeID =10000088) 

UnitCodeIN clause來動態數組的形式。 和第二部分課程代碼也有變盤點

回答

1

關閉我的頭頂,假設我們有以下輸入(和你是工作在C#):

var unitCodes = new List<string> { "FDFFSACA" ,"FDFFSCFSAA", "FDFOPTHCP3A" }; 
var traineeID = 10000088; 

這應該工作:

var result = (from us in db.UnitSet_Unit 
       where unitCodes.Contains(us.UnitCode) 
       && us.CourseCode == (from tc in db.Trainee_course 
            where tc.TraineeID == traineeID 
            select tc.CourseCode).Distinct().SingleOrDefault() 
       select us.CourseCode).Distinct(); 
+0

謝謝DavidG。這有助於我獲得實際的linq查詢。 – bhakti 2014-10-10 05:34:09