0

I'm looking at porting logic from a stored procedure to an EF model. The stored procedure optionally accepted a list of departments which would be searched. Effectively I'm dynamically building the search criteria (or trying to..).

I've got a parameter class which contains a List< string> DeptCodes which is passed to my Searcher class. I'm applying the constraints against a set of data IQueryable< SearchResult> dataList. If DeptCodes contains any items I want to apply a chained set of or-ed constraints (in SQL where (DeptCode in 'ABC' or DeptCode in 'DEF')).

I guess I want to create an expression tree but I'm not sure where to start (my LINQ skills aren't quite up to speed at the moment). Can anyone point me in the right direction or give me a little sample to get me started?

Thanks in advance

Dave
  • 3,581
  • 1
  • 22
  • 25

1 Answers1

1

I think PredicateBuilder could be a good solution.

Try to look at it.

as-cii
  • 12,819
  • 4
  • 41
  • 43
  • Thanks - this did work. If anyone else looks for the same solution, you'll also need to download LinqKit as the EF doesn't support Invoke nodes and this provides a workaround. – Dave Jan 10 '11 at 14:03