学习笔记: Expression表达式目录树详解和扩展封装

1. 表达式链接扩展封装,ORM常用 And  Or

/// <summary>
/// 表达式访问者
/// </summary>
public class ExpressionVisitorTest
{

    public static void Show()
     {
        

        #region 表达式链接
         {
             Expression<Func<People, bool>> lambda1 = x => x.Age > 5;
             Expression<Func<People, bool>> lambda2 = x => x.Id > 5;
             Expression<Func<People, bool>> lambda3 = lambda1.And(lambda2);
             Expression<Func<People, bool>> lambda4 = lambda1.Or(lambda2);
             Expression<Func<People, bool>> lambda5 = lambda1.Not();
             Do1(lambda3);
             Do1(lambda4);
             Do1(lambda5);
         }
         #endregion


     }
     #region PrivateMethod
     private static void Do1(Func<People, bool> func)
     {
         List<People> people = new List<People>();
         people.Where(func);
     }
     private static void Do1(Expression<Func<People, bool>> func)
     {
         List<People> people = new List<People>()
         {
             new People(){Id=4,Name="123",Age=4},
             new People(){Id=5,Name="234",Age=5},
             new People(){Id=6,Name="345",Age=6},
         };

        List<People> peopleList = people.Where(func.Compile()).ToList();
     }

    private static IQueryable<People> GetQueryable(Expression<Func<People, bool>> func)
     {
         List<People> people = new List<People>()
         {
             new People(){Id=4,Name="123",Age=4},
             new People(){Id=5,Name="234",Age=5},
             new People(){Id=6,Name="345",Age=6},
         };

        return people.AsQueryable<People>().Where(func);
     }
     #endregion
}

转载于:https://www.cnblogs.com/xtxtx/p/9162432.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值