Reputation: 13437
I have such this table:
position title
---------------------------
1 "t1"
2 "t1"
3 "t2"
4 "t1"
5 "t2"
I want to filter "t1" title but for positions that current position and next position have 1 difference. According this if I want first "t1" the result should be [1,2].
How I can write this query using linq 2 sql?
Upvotes: 1
Views: 257
Reputation: 1499770
Sounds like you want a self-join:
var query = from item1 in db.Items.Where(x => x.title == "t1")
from item2 in db.Items.Where(x => x.title == "t1")
where item1.position + 1 == item2.position
select item1; // Adjust however you want, e.g. new { item1, item2 }
Now I don't know whether that will actually work in SQL... but logically it's what you want.
Upvotes: 2