Entity Framework底层操作封装V2版本(3)

现在是附加的,组合查询需要的扩展类。大家知道lanmda表达式的组合条件比较麻烦,所以就加了一样一个类,方便进行组合查询:

[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Linq.Expressions;  
  6.   
  7. namespace JFrame.AccessCommon  
  8. {  
  9.     public static class PredicateExtensions  
  10.     {  
  11.   
  12.         public static Expression<Func<T, bool>> True<T>()  
  13.         {  
  14.             return f => true;  
  15.         }  
  16.   
  17.         public static Expression<Func<T, bool>> False<T>()  
  18.         {  
  19.             return f => false;  
  20.         }  
  21.         public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expression1, Expression<Func<T, bool>> expression2)  
  22.         {  
  23.             var invokedExpression = Expression.Invoke(expression2, expression1.Parameters.Cast<Expression>());  
  24.             return Expression.Lambda<Func<T, bool>>(Expression.Or(expression1.Body, invokedExpression), expression1.Parameters);  
  25.         }  
  26.         public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expression1, Expression<Func<T, bool>> expression2)  
  27.         {  
  28.             var invokedExpression = Expression.Invoke(expression2, expression1.Parameters.Cast<Expression>());   
  29.             return Expression.Lambda<Func<T, bool>>(Expression.And(expression1.Body, invokedExpression), expression1.Parameters);  
  30.   
  31.         }  
  32.     }  
  33. }  

http://blog.csdn.net/jacky4955/article/details/25412261

posted @ 2014-12-30 14:54  关中秦人  阅读(88)  评论(0编辑  收藏  举报