How to use Expression.IfThenElse in C#
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
精彩评论