LINQ和分页与DataTable - 不能跳过工作? [英] LINQ and paging with a DataTable - can't get Skip working?

查看:274
本文介绍了LINQ和分页与DataTable - 不能跳过工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这可能是一个愚蠢的问题,但我似乎无法弄清楚。我以为我会尝试使用LINQ对付一个DataTable。我得到我的查询工作,现在我试图实现一些简单的分页。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆