开发者

how to check next item in linq 2 sql query

开发者 https://www.devze.com 2023-03-18 05:16 出处:网络
I have such this table: positiontitle --------------------------开发者_如何学Go- 1\"t1\" 2\"t1\" 3\"t2\"

I have such this table:

position             title
--------------------------开发者_如何学Go-
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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消