首页 新闻 会员 周边

EF 拼接条件表达式

0
悬赏园豆:10 [已解决问题] 解决于 2016-07-31 13:50
/// <summary>
        /// Combines two given expressions by using the AND semantics.
        /// </summary>
        /// <typeparam name="T">The type of the object.</typeparam>
        /// <param name="first">The first part of the expression.</param>
        /// <param name="second">The second part of the expression.</param>
        /// <returns>The combined expression.</returns>
        public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second)
        {
            return first.Compose(second, Expression.AndAlso);
        }
        /// <summary>
        /// Combines two given expressions by using the OR semantics.
        /// </summary>
        /// <typeparam name="T">The type of the object.</typeparam>
        /// <param name="first">The first part of the expression.</param>
        /// <param name="second">The second part of the expression.</param>
        /// <returns>The combined expression.</returns>
        public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second)
        {
            return first.Compose(second, Expression.OrElse);
        }

        public static Expression<Func<T, bool>> AndForOr<T>(this Expression<Func<T, bool>> lambda, Expression<Func<T, bool>> first,
            Expression<Func<T, bool>> second)
        {
            return null;
        }

如上代码,我想拼接and 和or表达式,求解

hardy_Wang的主页 hardy_Wang | 初学一级 | 园豆:17
提问于:2015-02-03 17:48
< >
分享
最佳答案
0

AndForOr 这个方法实现了什么功能?

收获园豆:10
诶碧司 | 小虾三级 |园豆:1912 | 2015-02-04 11:00
 whereExpression.AndForOr(exp1,exp2);

类似于这种

hardy_Wang | 园豆:17 (初学一级) | 2015-02-04 11:09

@未找到对象: 不明白,你是想要达到A && B还是A || B还是其它逻辑?

诶碧司 | 园豆:1912 (小虾三级) | 2015-02-05 12:41
其他回答(1)
0

然后呢?

幻天芒 | 园豆:37175 (高人七级) | 2015-02-04 09:06
AndForOr 这个方法就是想写拼接,写不出来
支持(0) 反对(0) hardy_Wang | 园豆:17 (初学一级) | 2015-02-04 10:31

@未找到对象: 参考LinqKit和Predicate.cs的源码。http://www.albahari.com/nutshell/linqkit.aspx

支持(0) 反对(0) 幻天芒 | 园豆:37175 (高人七级) | 2015-02-04 11:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册