EntityFramework動態組合Lambda表達式做爲數據篩選條件

用EF作查詢,寫了一個基類,有一個通用的分頁查詢方法。spa

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(..)查詢.net

作多了就嫌煩了,網上找如何來動態組合lambda表達式code

吐槽下:百度真弱,找了半天都是讓.complain()轉換爲Func<TD, bool> whereLambda來執行,谷歌搜索下找到了滿意答案,偷懶直接附上查找結果的地址:blog

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

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

相關文章
相關標籤/搜索