1
我最近遇到了一些SQL代碼,看起來像這樣取與在連接條件使用LINQ
SELECT
a.Id,
b.Id,
c.Id,
d.Id,
b.Name,
d.Occupation,
FROM TableA a
JOIN TableB b ON a.Id = b.Id
JOIN TableC c ON b.Id = c.Id AND b.Name = a.Name
JOIN tableD d ON c.Id = d.Id AND c.Occupation = d.Occupation
我從來沒有使用AND將裏面相應的LINQ查詢連接像這樣(的情況下,我用的是實體框架和LINQ爲我的所有查詢)。我通常把我所有的與運算裏面有where子句是這樣的:
var query = from a in dbContext.TableA
join b in dbContext.TableB on a.Id equals b.Id
join c in dbContext.TableC on b.Id equals c.Id
join d in dbContext.TableD on c.Id equals d.Id
where b.Name = a.Name
where c.Occupation = d.Occupation
select new
{
AId = a.Id,
BId = b.Id,
CId = c.Id,
DId = d.Id,
BName = b.Name,
DOccupation = d.Occupation,
};
我可以使用哪些技術來得到我的LINQ查詢匹配上面的SQL語句?
這正是我所期待的。謝謝! – Halcyon