LINQ和分页与DataTable - 不能跳过工作? [英] LINQ and paging with a DataTable - can't get Skip working?
问题描述
DataTable dataTable = null;
dataTable = GetAllDataTables();
var query = from r in dataTable.AsEnumerable()
orderby r.Field< string>(Constants.fileName)
select r;
query.Skip(WPP_PAGE_SIZE * pageIndex).Take(WPP_PAGE_SIZE);
我的问题是我在query.Skip(...)中收到错误。 >
错误1'System.Data.OrderedEnumerableRowCollection'
不包含
'Skip'的定义,而没有扩展方法'跳过'
接受类型
'的第一个参数System.Data.OrderedEnumerableRowCollection'
可以找到(你错过了一个
使用指令或汇编
引用? )
参考文献我有:
- Microsoft.SharePoint
- 系统
- System.Core
- System.Data
- System.Data.DataSetExtensions
- System.Web
- System.Xml
我缺少什么?
您需要 .Linq;
在您的文件的顶部。
第二个问题是您需要分配Skip和取其他方式,结果只会被丢弃:
var query2 = query.Skip(WPP_PAGE_SIZE * pageIndex).Take(WPP_PAGE_SIZE) ;
Ok so this might be a dumb question, but I can't seem to figure it out. I thought I'd try out LINQ against a DataTable. I got my query working and now I'm trying to implement some simple paging.
DataTable dataTable = null;
dataTable = GetAllDataTables();
var query = from r in dataTable.AsEnumerable()
orderby r.Field<string>(Constants.fileName)
select r;
query.Skip(WPP_PAGE_SIZE * pageIndex).Take(WPP_PAGE_SIZE);
My problem is that I get an error at query.Skip(...).
Error 1 'System.Data.OrderedEnumerableRowCollection' does not contain a definition for 'Skip' and no extension method 'Skip' accepting a first argument of type 'System.Data.OrderedEnumerableRowCollection' could be found (are you missing a using directive or an assembly reference?)
References I have:
- Microsoft.SharePoint
- System
- System.Core
- System.Data
- System.Data.DataSetExtensions
- System.Web
- System.Xml
What am I missing?
You need using System.Linq;
at the top of your file.
A second problem is that you need to assign the result of Skip and Take to something otherwise the result is simply discarded:
var query2 = query.Skip(WPP_PAGE_SIZE * pageIndex).Take(WPP_PAGE_SIZE);
这篇关于LINQ和分页与DataTable - 不能跳过工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!