我有一个SQL查询,我想转换成Linq,但我无法弄明白。任何帮助将不胜感激。感谢
SELECT Distinct Name FROM Context
inner join Nodes_1 on
Context.Node1Id= Nodes_1.Id OR
Context.Node2Id= Nodes_1.Id
where Context.ContextId = 1
答案 0 :(得分:1)
JOIN
的 OR
只是UNION
两个单独查询JOIN
的{{1}}。
因此,要使用LINQ重现它,您应该连接两个linq查询。
或者你可以这样做:
var query = (from entry in Context
from node in Nodes_1
where node.Id==entry.Node1Id ||
node.Id==entry.Node2Id
where entry.ContextId==1
select entry.Name)
.Distinct();
答案 1 :(得分:1)
这应该适合你:
var something = (from a in Context.Where(i => i.ContextId == 1)
from b in Nodes_1
where (a.Node1Id == b.Id) || (a.Node2Id == b.Id)
select a.Name).Distinct();