开发者

Building up a query expression dynamically or

开发者 https://www.devze.com 2023-02-03 16:06 出处:网络
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

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 Sea开发者_高级运维rcher 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


I think PredicateBuilder could be a good solution.

Try to look at it.

0

精彩评论

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

关注公众号