zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Mybatis与Spring集成
    Mybatis 多对多
    Mybatis表关联多对一
    Mybatis表关联一对多
    Mybatis增删改查(CURD)
    Mybatis接口注解
    MyBatis环境配置及入门
    MyBatis教程
    Spring JDBC StoredProcedure类示例
    Spring JDBC SqlUpdate类示例
  • 原文地址:https://www.cnblogs.com/sjr10/p/3626931.html
Copyright © 2011-2022 走看看