2010-08-24 54 views
0
SELECT * 
FROM table1 JOIN table2 
ON table1.center BETWEEN table2.left AND table2.right 

我是LINQ新手,我看到'join'需要'equals'关键字(而不是我的SQL中的BETWEEN)。也许我可以重写'Equals'操作符并创建一个LINQ查询的新对象?这个SQL查询是否可以转换成LINQ?

+0

假设的问题是两列加入,看到了这个问题:http://stackoverflow.com/questions/345427/linq-to-sql-join-multiple-columns-from-the-same-table – Kobi 2010-08-24 08:48:04

回答

4

对于除等号以外的其他事情,请将您的连接条件放在where子句中。它与旧样式的SQL类似,您以笛卡尔联接开始,然后过滤where子句。

from t1 in table1 
from t2 in table2 
where t1.centre >= t2.left && t1.centre <= t2.right 
select new { ta.centre, t1.left}; //add more fields as required.