• 使用Entity Framework时动态生成lamda表达式


    public Expression<Func<Job, bool>> ToLambda()
            {
                Type type = typeof (Job);
                ParameterExpression parameterExpression = Expression.Parameter(type, "job");

                Expression body = Expression.Equal(Expression.Property(parameterExpression, "MemberId"), Expression.Constant(MemberId));

                if (Key.IsNotNullAndWhiteSpace())
                {
                    MemberExpression keyMember = Expression.Property(parameterExpression, "JobName");
                    Expression value = Expression.Constant(Key);
                    MethodCallExpression keyExpression = Expression.Call(keyMember,
                                                                              typeof (string).GetMethod("Contains"),
                                                                              value);
                    body = Expression.And(body, keyExpression);
                }

                if(IsOpen.HasValue)
                {
                    MemberExpression isOpenExpression = Expression.Property(parameterExpression, "IsOpen");
                    Expression openExpression = Expression.Equal(isOpenExpression, Expression.Constant(IsOpen));
                    body = Expression.And(body, openExpression);
                }

                return Expression.Lambda<Func<Job, bool>>(body, parameterExpression);
            }

  • 相关阅读:
    jsoup获取文章内容
    查询数据,更新数据
    查询数据,从链接地址中爬取文章内容jsoup
    java输出一个目录下的子目录
    从多层级的目录文件中查找字符串
    Win10 x64 pnglib Release
    Win10 x64 pnglib Debug
    VS2015 dlib编译 x64 Release .lib生成
    VS2015 dlib编译 x64 Debug .lib生成
    OpenBLAS编译 Release x64 Win10 vs2015
  • 原文地址:https://www.cnblogs.com/hyl8218/p/2443316.html
Copyright © 2020-2023  润新知