• 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         }
  • 相关阅读:
    vivado工程移植
    Search Everything 多项查找
    RTL_代码覆盖率
    在ARTIX-7上实现摄像头视频通路
    转:自动生成testbench
    转:winedt中显示中文
    Zynq和microblaze的区别
    转:找不到include xgpio.h;Unresolved include xgpio.h
    DHTMLX 常用技术
    Ubuntu中安装 mercurial – TortoiseHG
  • 原文地址:https://www.cnblogs.com/demoC/p/5107520.html
Copyright © 2020-2023  润新知