C#基础 Lambda

2021-01-03 06:28

阅读:636

标签:ble   blog   and   ssi   code   any   using   query   lam   

原文:https://www.cnblogs.com/Lau7/p/5451985.html

扩展类

public static class ExpressionExt
{
    public static Expression> And(this?Expression> expr1, Expression> expr2)
    {
        return Expression.Lambda>(Expression.AndAlso(expr1.Body, expr2.Body), expr1.Parameters);
    }
    public static Expression> Or(this?Expression> expr1,Expression> expr2)
    {
        return Expression.Lambda>(Expression.OrElse(expr1.Body, expr2.Body), expr1.Parameters);
    }
}

使用示例

Expression> exp1 = s => s.UserName.Contains("1") && s.Age > 0;
Expression> exp2 =exp1.And( s => s.IsEnable == 1);
using (var context = new DbContext().ConnectionString(connString))
{
    var result1 = context.Select(exp1).QueryMany();
    var result2 = context.Select(exp2).QueryMany();
}

C#基础 Lambda

标签:ble   blog   and   ssi   code   any   using   query   lam   

原文地址:https://www.cnblogs.com/guxingy/p/13207203.html


评论


亲,登录后才可以留言!