How can you update a Linq Expression with additional parameters?

前端 未结 5 947
感情败类
感情败类 2020-12-29 14:28

I have a Linq Expression, which may be altered depending on certain conditions. An example of what I would like to do (left blank the bit I am not sure about):



        
5条回答
  •  被撕碎了的回忆
    2020-12-29 14:50

    This all depends on how does ProjectRepository.Get() behave and what it returns. The usual way (for example, LINQ to SQL does something like this) is that it returns a IQueryable and lets you (among other things) add more Where() clauses before sending it to the server in the form of one SQL query, with all the Where() clauses included. If this is the case, Mark's solution (use IQuerybale) will work for you.

    But if the Get() method executes the query based on the filter immediately, you need to pass it the whole filter in the expression. To do that, you can use PredicateBuilder.

提交回复
热议问题