2017-09-27 34 views
0

我在LINQ是新的查詢 ,我需要幫助,我的樣本SQL查詢轉換爲LINQ拉姆達查詢如何轉換SQL內連接來拉姆達LINQ查詢

select * from GRecommendations 
inner join GSections 
on GRecommendations.GSectionId = GSections.Id 
where GSections.GaId = 646 
+0

我們不是要轉換的代碼爲您服務。如果你嘗試過,並且你被困在某個地方,那麼你非常歡迎告訴哪裏*特別是*你需要幫助。一個明顯的建議:不要在LINQ中加入,使用導航屬性。 –

+0

是的,你是對的 –

回答

2

有兩種不同的方法,你可以使用時GRecommendations是一個集合。

var arrResult = //UNTESTED 
    GRecommendations 
    .Join(GSections.Where(sec => sec.GaId.Equals(646)), 
    rec => rec.GeSectionId, 
    sec => sec.Id, 
    (REC, SEC) => new { /*put here what you want selected*/ } 
    ); // 

var arrResult = 
(
    from rec in GRecommendations 
    join rec in GSections.Where(s => s.GaId.Equals(646)) on rec.GSectionId equals sec.GaId 
    select new {/*rec.something*/, /*sec.something*/} 
);