开发者

how to check next item in linq 2 sql query

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜