在Linq where子句中使用Row_Number[英] Using Row_Number in Linq where clause

本文是小编为大家收集整理的关于在Linq where子句中使用Row_Number的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

如何使用 linq 模拟以下 sql 查询.我只想有一个 Row_Number 列并在 linq where 子句中使用它的值.

With t As (
    Select Row_Number() over ( Order by Id ) as 'RowId', * From Orders
) 
Select * From t Where RowId between 1 and 10

推荐答案

我认为您要做的只是 Skip/Take,用于分页.

所以基本上:

var result = dataContext.Products.Skip(0).Take(10).ToList();

(代码未经测试,在我脑海中写下)

本文地址:https://www.itbaoku.cn/post/1556939.html

问题描述

how can I simulate the following sql query using linq. I just want to have a Row_Number column and use it's values in linq where clause.

With t As (
    Select Row_Number() over ( Order by Id ) as 'RowId', * From Orders
) 
Select * From t Where RowId between 1 and 10

推荐答案

I think what you're trying to do is just Skip/Take, for paging.

So basically:

var result = dataContext.Products.Skip(0).Take(10).ToList();

(Code is untested, written off the top of my head)