• “拼接”linq查询


    static void Main(string[] args)
            {
                List<Person> list = new List<Person>() { 
                    new Person(){ Age=20, Name="wengyuli", Parts=new Part(){ Name="123"}},
                    new Person(){ Age=30, Name="chenyang", Parts=new Part(){ Name="123456"}},
                    new Person(){ Age=40, Name="heshuai", Parts=new Part(){ Name="123"}},
                    new Person(){ Age=50, Name="heyunlong", Parts=new Part(){ Name="123456"}}
                };
    
                var c = Expression.Parameter(typeof(Person), "m");
    
                Expression condition = Expression.Constant(false);
    
    
                Expression con = Expression.Call(
                    Expression.Property(c,typeof(Person).GetProperty("Name")),
                    typeof(string).GetMethod("StartsWith",new Type[]{typeof(string)}),
                    Expression.Constant("wengyuli"));
    
                condition = Expression.Or(con, condition); 
                Expression<Func<Person, bool>> end = Expression.Lambda<Func<Person, bool>>(condition, new ParameterExpression[] { c });
            }
            
            class Person
            {
                public string Name { set; get; }
                public int Age { set; get; }
                public Part Parts { set; get; }
            }
    
            class Part
            {
                public string Name { set; get; }
            }
        }
  • 相关阅读:
    团队项目-个人博客-4.25
    团队项目-个人博客-4.24 学习进度08
    评价使用的输入法
    个人工作总结08
    个人工作总结07
    第八周学习进度条
    个人工作总结06
    构建之法阅读笔记04
    个人工作总结05
    个人工作总结04
  • 原文地址:https://www.cnblogs.com/wengyuli/p/1871134.html
Copyright © 2020-2023  润新知