使用linq在其他结果查询中查询
本文关键字:查询 结果 其他 linq 使用 | 更新日期: 2023-09-27 18:07:18
我在EF中使用linq查询遇到问题。
基本上,我要做的是这样,在普通的SQL:
SELECT
t2.*
FROM
[SHP_Console2].[dbo].[Domain] t1
INNER JOIN
[SHP_Console2].[dbo].[Domain] t2
ON t2.[left] >=t1.[left] AND t2.[right]<=t1.[right]
WHERE
t1.ID =1
我不能用linq做这个。
I'm string this
from a in DomainRep.Where(c => c.ID == domainID).Select(c => new { c.left, c.right })
from b in DomainRep.Where(x => x.left >= a.left && x.right <= a.right)
select a;
我做错了什么?
您将查询与匿名类型混合。你不能这样做。
你也不能使用JOIN
和>=
条件- LINQ不支持这种语句。但是,可以使用其他语法来完成。
from a in DomainRep
from b in DomainRep
where b.left >= 1.left && b.right <= a.right && a.ID = 1
select b;
编辑:参考:http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/428c9db2-29f6-45d8-ab97-f00282397368/
var query = (from a in DomainRep
from b in DomainRep
where a.left >= b.left
select b)
.ToList();