我有下面的linq查询。
(from q in table1
join u1 in table2 on q.Field1 = u1.Id
join u2 in table2 on q.Field2 = u2.Id
join u3 in table2 on q.Field3 = u3.Id
select q.Id, u1.Name, u2.Name, u3.Name)
您可以看到,在table2上有3次联接,而table1上的列不同。
在table2上进行单连接是否可以实现上述结果?
谢谢 伊姆兰森
答案 0 :(得分:0)
用匿名对象替换其他join
:
var query = from q in table1
join u1 in table2
on new { q.Field1, q.Field2, q.Field3 } equals
new { u1.Id, u1.Id, u1.Id }
select new {q.Id, u1.Name};
或带有where
s:
var query = from q in table1
join u1 in table2 on q.Field1 equals u1.Id
where q.Field2 == u1.Id &&
q.Field3 == u1.Id
select new {q.Id, u1.Name};