IQuerable

标签: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

版权声明:完美者 发表于 2020-12-29 11:32:07。
转载请注明:IQuerable | 完美导航

暂无评论

暂无评论...