How to set more than 2 Expression in Expression.Or

2020-04-03 13:16发布

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.

2条回答
在下西门庆
2楼-- · 2020-04-03 13:17

You can also use || instead of Or( ) or Disjunction( ).

查看更多
男人必须洒脱
3楼-- · 2020-04-03 13:31

Use Disjunction instead of Or.

查看更多
登录 后发表回答