Linq2Sql通过多列连接(通过OR操作符)
本文关键字:通过 OR 操作符 连接 Linq2Sql | 更新日期: 2023-09-27 18:13:29
现在我可以翻译了:
SELECT *
FROM vectors as v
INNER JOIN points as p
ON v.beginId = p.id OR v.endId = p.id
Into linq2sql语句?我想要这样写:
var query = from v in dc.vectors
join p in dc.points on p.id in (v.beginId, v.endId)
...
select ...;
我知道,我可以通过Union构造来完成这个任务,但是有没有比复制大部分查询更好的方法呢?
在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 };
相当于:
的sqlSELECT *
FROM vectors as v,
points as p
WHERE v.beginId = p.id
OR v.endId = p.id