码迷,mamicode.com
首页 > 其他好文 > 详细

IQuerable

时间:2020-12-29 11:32:07      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:query   yacc   open   turn   exp   rgb   倒序   color   ati   

技术图片
 1  #region 正序
 2         /// <summary>
 3         /// 正序
 4         /// </summary>
 5         /// <typeparam name="T"></typeparam>
 6         /// <param name="source"></param>
 7         /// <param name="ordering">列名</param>
 8         /// <returns></returns>
 9         public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string ordering)
10         {
11             var type = typeof(T);
12             var property = type.GetProperty(ordering);
13             var parameter = Expression.Parameter(type, "p");
14             var propertyAccess = Expression.MakeMemberAccess(parameter, property);
15             var orderByExp = Expression.Lambda(propertyAccess, parameter);
16             MethodCallExpression resultExp = Expression.Call(typeof(Queryable), "OrderBy", new Type[] { type, property.PropertyType }, source.Expression, Expression.Quote(orderByExp));
17             return source.Provider.CreateQuery<T>(resultExp);
18         }
19         #endregion
20 
21         #region 倒序
22         /// <summary>
23         /// 倒序
24         /// </summary>
25         /// <typeparam name="T"></typeparam>
26         /// <param name="source">数据源</param>
27         /// <param name="ordering">列名</param>
28         /// <returns></returns>
29         public static IQueryable<T> OrderByDescending<T>(this IQueryable<T> source, string ordering)
30         {
31             var type = typeof(T);
32             var property = type.GetProperty(ordering);
33             var parameter = Expression.Parameter(type, "p");
34             var propertyAccess = Expression.MakeMemberAccess(parameter, property);
35             var orderByExp = Expression.Lambda(propertyAccess, parameter);
36             MethodCallExpression resultExp = Expression.Call(typeof(Queryable), "OrderByDescending", new Type[] { type, property.PropertyType }, source.Expression, Expression.Quote(orderByExp));
37             return source.Provider.CreateQuery<T>(resultExp);
38         } 
39         #endregion
View Code

 

IQuerable

标签:query   yacc   open   turn   exp   rgb   倒序   color   ati   

原文地址:https://www.cnblogs.com/ABC-wangyuhan/p/14180172.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!