Reputation: 11
I'm getting a problem with a query with linq in EF.
Basically, what i'm tring to do is this, in plain 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
I'm not able to do this with linq.
I'm tring 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;
What i'm doing wrong?
Upvotes: 1
Views: 79
Reputation: 7068
Edit: Reference: 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();
Upvotes: -1
Reputation: 125620
You mixed your query with anonymous types. You can't do that this way.
You also can't use JOIN
with >=
condition - LINQ does not support that kind of statements. However, it can be done using alternative syntax.
from a in DomainRep
from b in DomainRep
where b.left >= 1.left && b.right <= a.right && a.ID = 1
select b;
Upvotes: 2