我希望有人使用过来自 Troy Goode 的非常优秀的PagedList?我实际上在 Winforms 应用程序中使用它,虽然它确实有效,但我失去了对它进行排序的能力。
返回 PagedList、控制页面和大小以及绑定到 DataGridView 没有问题,但我最关心的是排序。现在我也遇到了 Muhammad Mosa 的 SortedPageList,但我真的是与参数要求之一混淆。我正在使用私有方法返回 SortedPageList,但下面的代码似乎不起作用:
private SortedPagedList<Location, Location> GetInactiveLocationData(int Index, int Size) {
sysDataContext ctx = new sysDataContext();
try {
var query = ctx.Location.Where(x => x.Active == false).AsQueryable();
return query.ToPagedList(Index, Size, i => i, false);
//return new SortedPagedList<Location, Location>(query, Index, Size, i => i , true);
}
catch (Exception) {
throw;
}
}
这会引发错误“无法按类型排序:位置
”。显然,我想处理用户单击列标题以对该列进行排序的情况。
我知道解决方案涉及的 Lambda 表达式超出了我的知识水平(尽管承认这一点很尴尬),但我在这方面完全一无所知!我非常重视您对上述问题的建议!
感谢你!
Im hoping that someone has used the very excellent PagedList from Troy Goode? Im actually using it in a Winforms app, and while it does work, I have lost the ability to sort it.
Returning a PagedList, controlling the Page and Size, and binding to a DataGridView is no issue, but my biggest concern is Sorting. Now I have also come across the SortedPageList by Muhammad Mosa, but I really am confused with one of the parameter requirements. I am using a private method to return a SortedPageList, but my code below does not seem to work:
private SortedPagedList<Location, Location> GetInactiveLocationData(int Index, int Size) {
sysDataContext ctx = new sysDataContext();
try {
var query = ctx.Location.Where(x => x.Active == false).AsQueryable();
return query.ToPagedList(Index, Size, i => i, false);
//return new SortedPagedList<Location, Location>(query, Index, Size, i => i , true);
}
catch (Exception) {
throw;
}
}
This throws an error "Cannot order by type: Location
". Obvously, I would like to handle the case where the user clciks a column header to sort on that column.
I know that the solution involves Lambda Expressions above a level of knowledge I have (embarrassing as it is to admit) and I am completely clueless on this front! I would really value your advice on the abovementioned!
Thank u!
发布评论
评论(2)
那么,您可以首先学习一些基本 LINQ 操作(向下滚动或此处:LINQ 第 1 部分 -过滤和排序对象列表
一旦你发现了它的魔力,你就会飞起来:P
Well, you can start by learning some basic LINQ operations (scroll down to the "ordering" portion. Or here: LINQ Part 1 - Filtering & Sorting Object Lists .
Once you discover the magic, you'll fly :P
好吧,我觉得自己像个白痴!...好吧,有点像!我得到了以下工作:
现在,排序表达式在此处描述为
o =>; o.截止日期
。这太棒了,虽然这确实有效,但我现在正在尝试找到一种方法来创建一个通用函数,该函数将允许我:一种类似于以下内容的方法:
这可能吗?
另外一件事(如果它会帮助你帮助我)SortedPageList 方法看起来像这样:
How do I express
System.Linq.Expressions.Expression>
as a type that可以作为参数传递吗?OK, I feel like an idiot!...well, somewhat! I got the following to work:
Now, the sort expression is described here as
o => o.DueDate
. This is great, and while this does work, Im trying to now find a way to create a generic function that will allow me:A mehod that looks something like the following:
Is this possible?
One thing additionally (if it will help you help me) the SortedPageList method looks like so:
How do I express
System.Linq.Expressions.Expression<Func<T, TResult>>
as a type that can be passed as a parameter?