zoukankan      html  css  js  c++  java
  • 使用Linq to sql 和Linq to entity 时候写的拓展方法

    public static class PredicateBuilder
    {
    public static Expression<Func<T, bool>> True<T>() { return f => true; }
    public static Expression<Func<T, bool>> False<T>() { return f => false; }

    public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
    Expression<Func<T, bool>> expr2)
    {
    var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
    return Expression.Lambda<Func<T, bool>>
    (Expression.Or(expr1.Body, invokedExpr), expr1.Parameters);
    }

    public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1,
    Expression<Func<T, bool>> expr2)
    {
    var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
    return Expression.Lambda<Func<T, bool>>
    (Expression.And(expr1.Body, invokedExpr), expr1.Parameters);
    }

    public static Predicate<T> ConvertToPredicate<T>(this Func<T, bool> func)
    {
    return new Predicate<T>(func);
    }
    }

  • 相关阅读:
    第11次作业
    第十次作业
    找回感觉的练习
    Tomact学习笔记
    移动端问题小计
    节流和防抖函数
    requestAnimationFrame动画封装
    svg实现渐变进度圆环
    手机端判断安卓,iso,微信
    git常用指令
  • 原文地址:https://www.cnblogs.com/fjzhang/p/mushroom_Core.html
Copyright © 2011-2022 走看看