I'm trying to use PredicateBuilder to compose dynamic linq queries. In my object, I have a list of "Statuses" and I have another list of statuses that I want to search for.
So I need to be able to look in my object.Status property (a list) and see if it contains any of the items in my query list.
I've been fiddling around with .Any() and .Contains() but can't seem to find the right syntax.
What am I doing wrong? Below are some of the things I've tried, but none of them have the correct syntax.
myObject.Statuses.Contains(myStatusList);
myObject.Statuses.Any(myStatusList);
myObject.Statuses.Any(s => s == myStatusList);
got.Any(x => want.Contains(x))
On further reflection, however, I'd write a ContainsAny
extension method, to make this more readable. The implementation would probably be the same (although want.Intersect(got).Any()
would also work).
Do you mean:
myObject.Statuses.Any(s => myStatusList.Contains(s));
? This would be equivalent too:
myStatusList.Any(s => myObject.Statuses.Contains(s));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With