如何结合(OR)两个表达式树 [英] How to combine (OR) two expression trees

查看:164
本文介绍了如何结合(OR)两个表达式树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类型的两个表达式树:表达式来; Func键<字符串,布尔>> ,我想获得一个单一的表达,会做的的OR两个表达式(传递相同的字符串参数两个表达式)
你知道吗?

I have two expression trees of type : Expression<Func<string, bool>> and I would like to obtain a single Expression that will do the OR of the two expressions (passing the same string parameter to both expressions) Any idea?

推荐答案

您可以使用的 PredicateBuilder 做到这一点。例如:

You can use PredicateBuilder from LINQKit to do this. For example:

Expression<Func<string, bool>> e1 = …;
Expression<Func<string, bool>> e2 = …;
Expression<Func<string, bool>> combined = e1.Or(e2).Expand();

这篇关于如何结合(OR)两个表达式树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆