I have a table that looks like this:
UserID | FruitID
4 | 34
4 | 4355
4 | 652
5 | 5677
5 | 562
4 | 562
For now, I’m passing a UserID and a FruitID like this:
var IsAuthorized = MyDC.FruitTable
.Any(f => f.UserID == TheUserID &&
f.FruitID == TheFruitID);
This returns a boolean. Now I want to write the same thing for a list of FruitID: I pass in a UserID and a several FruitIDs and I want a boolean that says "ALL the FruitIDs have a UserID == to the TheUserID".
Note that if a list contains just one element that doesn’t match
FruitID == f.FruitID && f.UserID == UserID then the return should be
false for the entire list.
How do I rewrite my query to take in a list of FruitIDs?
Leaving the fact that your sample code wouldn’t compile, I suspect you want something like:
This will check that every entry such that the fruit ID is in the given list also matches the specified user ID. There are alternative ways of writing it, of course.
It doesn’t check that every entry in the original collection has a valid fruit ID. It’s not clear from the question whether that was the aim or not…