Reputation: 287
I have a list MyGroups and a string 'AllowedGroups'.
For example I have string in MyGroups.Name = "Admin Only" and AllowedGroups ="Admin Only, Normal Group". I can't understand why the following expression evaluates to false when it should be true:
model.MyGroups.Any(m => m.Name.Contains(AllowedGroups)
Upvotes: 0
Views: 73
Reputation: 30636
I think what you need, based on the information you've provided, is the opposite of what you have.
Something like this:
var allowedGroupsArray = AllowedGroups.Split(',');
var result = model.MyGroups.Any(m => allowedGroupsArray.Contains(m.Name));
Specifically, using Array.Contains()
inside the .Any()
call should generate basically a WHERE ... IN
type clause in your SQL.
Upvotes: 6
Reputation: 1235
it returns false because Admin Only does not contain Admin Only, Normal Group
Upvotes: 0