结合几个表达式< func< t,bool>

发布于 2025-01-30 17:49:42 字数 774 浏览 3 评论 0原文

我有5个表达式< func< t,bool>在Azure存储表中过滤数据。我需要将所有这些结合起来。

Expression<Func<T,bool>> x = (e => e.a < value))
Expression<Func<T,bool>> y = ...
Expression<Func<T,bool>> z = ...
Expression<Func<T,bool>> a = ...
Expression<Func<T,bool>> b =..

现实中的表达很复杂,因此用大量或很难阅读和理解一个表达。所以我写了5个表情。现在我需要做类似的事情:(

b and((x and y)或(z and a)))

x和y,z以及以下方式进行

var XYcombined = Expression.And(Expression.Invoke(x,parameter), Expression.Invoke(y,parameter)
var ZAcombined = Expression.And(Expression.Invoke(z,parameter), Expression.Invoke(a,parameter)
var ORcombined = Expression.Or(XYcombined, ZAcombined)

我已经按照 表达式,我尝试使用表达式和表达式和表达,但是Azure返回HTTP 500。

I have 5 Expression<Func<T,bool> to filter data in Azure storage table. I need to combine all of them.

Expression<Func<T,bool>> x = (e => e.a < value))
Expression<Func<T,bool>> y = ...
Expression<Func<T,bool>> z = ...
Expression<Func<T,bool>> a = ...
Expression<Func<T,bool>> b =..

Expression in reality are complex, so writing one expression with lot of or,and will be difficult to read and understand. So I wrote 5 expression. Now I need to do something like this :

(b and ((x and y) or (z and a)))

I already did x and y, z and a in following way :

var XYcombined = Expression.And(Expression.Invoke(x,parameter), Expression.Invoke(y,parameter)
var ZAcombined = Expression.And(Expression.Invoke(z,parameter), Expression.Invoke(a,parameter)
var ORcombined = Expression.Or(XYcombined, ZAcombined)

now I need to somehow combine ORcombined with one more expression, I tried to use Expression.And and Expression.AndAlso, but azure returns http 500.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文