Lambda动态排序
private static IList<T> IListOrderBy<T>(IList<T> list, string propertyName) where T : new()
{
if (list == null || list.Count == 0)
{
return list;
} Type elementType = Queryable.AsQueryable(list).ElementType;
//PropertyInfo propertyInfo = elementType.GetProperty(propertyName);
ParameterExpression parameter = Expression.Parameter(elementType, "");
Expression body = Expression.PropertyOrField(parameter, propertyName); Expression sourceExpression = list.AsQueryable().Expression; //Type sourcePropertyType = propertyInfo.PropertyType;
var selector = Expression.Lambda(body, parameter); Expression lambda = Expression.Call(typeof(Queryable), "OrderBy", new Type[]
{
elementType,
selector.Body.Type
}, sourceExpression, selector); //Expression lambda = Expression.Call(typeof(Queryable), "OrderBy", new Type[]
//{
// elementType,
// sourcePropertyType
//}, sourceExpression, Expression.Lambda(body, parameter));
var query = list.AsQueryable().Provider.CreateQuery<T>(lambda);
return query.ToList<T>(); }
Lambda动态排序的更多相关文章
- Lambda动态排序分页通用方法
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; us ...
- Lambda动态排序通用方法
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; us ...
- linq扩展之动态排序
前两天看QQ群里面,一位朋友问的问题,说在linq中怎么实现动态排序呢,自己想了半天,没有头绪,网上找了下相关的资料,看了下,收益挺多,记录下来. 之前我们没有如果不知道动态排序的方法的话,我们可能会 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(17)-LinQ动态排序
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(17)-LinQ动态排序 首先修复程序中的一个BUG这个BUG在GridPager类中,把sord修改为s ...
- LinQ动态排序
LinQ动态排序 首先修复程序中的一个BUG这个BUG在GridPager类中,把sord修改为sort这个名称填写错误,会导致后台一直无法获取datagrid的排序字段 本来是没有这一讲的,为了使2 ...
- ActiveReports 报表应用教程 (9)---交互式报表之动态排序
在 ActiveReports 中除了提供对数据源进行排序的功能之外,还提供了最终用户排序功能,最终用户可以对报表进行区域内排序和整个数据源排序,结合数据钻取.过滤等功能可以让用户更方便地分析报表数据 ...
- excel动态去重和动态排序
其实去重和排序的方法很多,没有哪一种更好,实时去重总会省一些时间,刚好也练习了下数组公式 动态去重: =IF(ROW()<=COUNTA(员工基础数据!H:H),INDEX(员工基础数据!H:H ...
- php sortable 动态排序
php sortable 动态排序未分页版.php 预览图: <?php mysql_connect("localhost","root","r ...
- 写一个针对IQueryable<T>的扩展方法支持动态排序
所谓的动态排序是指支持任意字段.任意升序降序的排序.我们希望在客户端按如下格式写: localhost:8000/api/items?sort=titlelocalhost:8000/api/item ...
随机推荐
- (原创)c++11中的日期和时间库
c++11提供了日期时间相关的库chrono,通过chrono相关的库我们可以很方便的处理日期和时间.c++11还提供了字符串的宽窄转换功能,也提供了字符串和数字的相互转换的库.有了这些库提供的便利的 ...
- 每日英语:The best time for coffee is 10:30 a.m.
For many of us, it is the rocket fuel that gets us going first thing in the morning. But one expert ...
- Delphi下IOCP开源框架:DIOCP 成功应用案例分享
首先说明,该项目不是本人的项目,本文转自盒子. 该项目使用的DIOCP版本为1.0,目前diocp为3.5 以下是盒子的原文 ------------------------------------- ...
- kindeditor自定义插件插入视频代码
kindeditor自定义插件插入视频代码 1.添加插件js 目录:/kindeditor/plugins/diy_video/diy_video.js KindEditor.plugin('diy_ ...
- Asp.Net正则获取链接地址
string html = “html代码”; Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?< ...
- Oracle事务与锁
Oracle事务与锁 2017-12-13 目录 1 数据库事务概括 1.1 事务定义 1.2 事务生命周期 1.3 事物的特性 1.4 死锁2 事务相关语句 2.1 事务相关语句概括 2 ...
- iis部署wcf服务
win8的如下 . 打开iis新建一个应用程序MyWcfTest 检查iis中的处理程序映射,含有svc说明激活了. 然后把svc文件和webconfig放入到指定的目录上. 使用地址http://l ...
- Writing your first Django
Quick install guide 1.1 Install Python, it works with Python2.6, 2.7, 3.2, 3.3. All these version ...
- Bitcoin A First Assessment
1. What is BitcoinBitcoin is a digital currency designed by Satoshi Nakamoto. Bitcoin allows users t ...
- NETCONF+Yang配置TSN
NETCONF用来替换SNMP,是一个网管协议.YANG是NETCONF的数据建模语言,可以使用Yang模式的文本配置网关,从而通过NETCONF协议管理网关. NETCONF+Yang可用于TSN( ...