问题描述
割草机我可以翻译以下内容:
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 ...;
我知道,我可以通过工会建设做这种肮脏的事情,但是有比复制大多数查询更好的方法吗?
推荐答案
您在Linq-to-sql中不能使用or> on子句.您需要做:
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
问题描述
Mow I can translate this:
SELECT * FROM vectors as v INNER JOIN points as p ON v.beginId = p.id OR v.endId = p.id
Into linq2sql statement? Basically I want this:
var query = from v in dc.vectors join p in dc.points on p.id in (v.beginId, v.endId) ... select ...;
I know, I can do this dirty through Union construction, but is there a better way than duplicating most of the query?
推荐答案
You can't have an on clause in linq-to-sql with an or. You need to do:
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 };
Equivalent to the sql of:
SELECT * FROM vectors as v, points as p WHERE v.beginId = p.id OR v.endId = p.id