开发者

How to use Expression.IfThenElse in C#

开发者 https://www.devze.com 2023-03-21 13:14 出处:网络
I have a method in a repository: Query<T>(System.L开发者_开发知识库inq.Expressions.Expression<Func<T,bool>> function)

I have a method in a repository:

Query<T>(System.L开发者_开发知识库inq.Expressions.Expression<Func<T,bool>> function)

When i call it, I want to use different Expressions based on a condition.

I tried:

m_Repository.Query<MyObject>(x => x.Infos.Count > 1 ? 
x.Infos.Any(y => y.Info.Name.StartsWith(s)) :
x.Name.StartsWith(s));

but then it always executes the else part. I figured I had to use Expression.IfThenElse, but I cannot make it work. Any suggestions on how to do this?

Thanks!


Have you tried Expression.Condition

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号