• Linq语句 动态组建


     1        public override System.Linq.Expressions.Expression<Func<I_Position_Access, bool>> GetWhereLambda(I_Position_Access t)
     2         {
     3             ParameterExpression parameter = Expression.Parameter(typeof(I_Position_Access), "b");//创建参数b
     4             System.Linq.Expressions.ConstantExpression constant = Expression.Constant(t.I_Position_AccessID);//创建常数 
     5             MemberExpression member = Expression.PropertyOrField(parameter, "I_Position_AccessID");
     6 
     7             System.Linq.Expressions.BinaryExpression bin =
     8                 Expression.GreaterThan(member, constant);//创建 i > 常数 
     9 
    10             if (t.I_Position_AccessID > 0)
    11             {
    12                 constant = Expression.Constant(t.I_Position_AccessID);
    13                 member = Expression.PropertyOrField(parameter, "I_Position_AccessID");
    14                 bin = Expression.Equal(member, constant);
    15             }
    16             if (t.I_PositionID > 0)
    17             {
    18                 constant = Expression.Constant(Convert.ToInt32(t.I_PositionID), typeof(int?));
    19                 member = Expression.PropertyOrField(parameter, "I_PositionID");
    20                 System.Linq.Expressions.BinaryExpression where2 = Expression.Equal(member, constant);
    21 
    22                 bin = Expression.And(bin, where2);
    23             }
    24             if (t.I_AccessID > 0)
    25             {
    26                 constant = Expression.Constant(Convert.ToInt32(t.I_AccessID), typeof(int?));
    27                 member = Expression.PropertyOrField(parameter, "I_AccessID");
    28                 System.Linq.Expressions.BinaryExpression whereI_AccessID = Expression.Equal(member, constant);
    29                 bin = Expression.And(bin, whereI_AccessID);
    30             }
    31             if (t.OpenState > 0)
    32             {
    33                 constant = Expression.Constant(Convert.ToInt32(t.OpenState), typeof(int?));
    34                 member = Expression.PropertyOrField(parameter, "OpenState");
    35                 System.Linq.Expressions.BinaryExpression whereOpenState = Expression.Equal(member, constant);
    36                 bin = Expression.And(bin, whereOpenState);
    37             }
    38             return Expression.Lambda<Func<I_Position_Access, bool>>(bin, parameter);
    39             //获取Lambda表达式
    40         }
  • 相关阅读:
    WorkFlow
    自己写的一个多线程的consumer 和 producter 模式
    Visual Studio进行Web性能测试
    基元线程同步——内核模式构造
    系统架构师
    《构建高性能的web站点》读书笔记缓存
    python中的代码对象
    python web框架互相融合, Pyramid或取代Django
    海量数据处理专题
    Django框架学习Forms篇
  • 原文地址:https://www.cnblogs.com/demoC/p/5107520.html
Copyright © 2020-2023  润新知