我是LINQ查询的新手 我需要帮助将我的示例SQL查询转换为LINQ lambda查询
select * from GRecommendations
inner join GSections
on GRecommendations.GSectionId = GSections.Id
where GSections.GaId = 646
答案 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*/}
);