我可以翻译一下:
SELECT *
FROM vectors as v
INNER JOIN points as p
ON v.beginId = p.id OR v.endId = p.id
进入linq2sql语句?基本上我想要这个:
var query = from v in dc.vectors
join p in dc.points on p.id in (v.beginId, v.endId)
...
select ...;
我知道,我可以通过Union构建来做到这一点,但有没有比复制大部分查询更好的方法?
答案 0 :(得分:2)
在linq-to-sql中,on
不能有or
子句。你需要这样做:
var result = from v in dc.vectors
from p in dc.points
where p.id == v.beginId || p.id == v.endId
select new { v, p };
相当于sql:
SELECT *
FROM vectors as v,
points as p
WHERE v.beginId = p.id
OR v.endId = p.id