本文介绍了如何在Expression中设置2个以上的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个具有超过3-4个Expression.Or的查询?但是表达式只是让我在里面添加两个表达式。 if(!string.IsNullOrEmpty(keyword))
query
.Add(Expression.Or(
Expression.Like(Name,keyword,MatchMode.Anywhere),
Expression.Like(LastName,keyword,MatchMode.Anywhere ))
.Add(Expression.Or(
Expression.Like(Email1,keyword,MatchMode.Anywhere),
Expression.Like(Email2,keyword,MatchMode.Anywhere )));
上面的代码生成%this%或LastName的名称,如%this% AND Email1 like%this%and Email2 like%this。
提前感谢
解决方案
使用,而不是或。
I want to create a query which has more than 3-4 Expression.Or ? But Expression.Or just let me to add two Expressions inside it.
if (!string.IsNullOrEmpty(keyword))
query
.Add(Expression.Or(
Expression.Like("Name", keyword, MatchMode.Anywhere),
Expression.Like("LastName", keyword, MatchMode.Anywhere)))
.Add(Expression.Or(
Expression.Like("Email1", keyword, MatchMode.Anywhere),
Expression.Like("Email2", keyword, MatchMode.Anywhere)));
The code above generates "Name like %this% or LastName like %this% AND Email1 like %this% and Email2 like %this.
Thanks in advance.
解决方案
Use Disjunction instead of Or.
这篇关于如何在Expression中设置2个以上的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!