Linq的排序一般是这样写的: query.OrderBy(x => x.Tel).Skip().Take(); 实际使用中排序字段可能是通过字符类型的参数来设置的,于是想这样实现: query.OrderBy(x=>x.GetType().GetField().Take(); 上面的写法是无法编译通过的,此路不通,于是找到一个order扩展类: using System; using System.Linq; using System.Linq.Expressions; using Syst…
http://www.albahari.com/nutshell/predicatebuilder.aspx Dynamically Composing Expression Predicates Suppose you want to write a LINQ to SQL or Entity Framework query that implements a keyword-style search. In other words, a query that returns rows who…
public static class PredicateExtensions { public static Expression<Func<T, bool>> True<T>() { return f => true; } public static Expression<Func<T, bool>> False<T>() { return f => false; } public static Expression&…