EntityFramework动态组合Lambda表达式作为数据筛选条件

用EF做查询,写了一个基类,有一个通用的分页查询方法。

public virtual ListViewResponseResult<TV> GetEntitys<TS>(int pageIndex, int pageSize, int fId, Expression<Func<TD, bool>> whereLambda, Expression<Func<TD, TS>> orderByLambda, bool isAsc)
{
     ..............
    var temp = Repository.GetEntitysByFId(fId);
     if (whereLambda != null)
     {
          temp = temp.Where(whereLambda);
     }
     ..............  
}

以前遇到需要动态组合lambda表达式时候,都不知道如何办,只能重写基类方法用 where(..).where(..)查询

做多了就嫌烦了,网上找如何来动态组合lambda表达式

吐槽下:百度真弱,找了半天都是让.complain()转换为Func<TD, bool> whereLambda来执行,谷歌搜索下找到了满意答案,偷懒直接附上查找结果的地址:

http://blog.csdn.net/leewhoee/article/details/8968023

http://blogs.msdn.com/b/meek/archive/2008/05/02/linq-to-entities-combining-predicates.aspx

 

 

 

posted @ 2014-03-26 20:34  sjR10  阅读(1097)  评论(0编辑  收藏  举报