Use of "Any" in memberOf search

Jan 27, 2014 at 11:10 PM
Edited Jan 27, 2014 at 11:13 PM
I am trying to return a list of users where any of the groups they are a member of is in given array of groups.

In my User object, I have a Groups property, as an array of strings, mapped to the "memberOf" attribute:
[DirectoryAttribute("memberOf")]
public string[] Groups { get; set; }
Given an array of strings that represent the groups, called "groups", the following does not work:
var users = context.Query<User>().Where(u => u.Groups.Any(g => groups.Contains(g)));
The error states that Any is not supported. Is there another way to do this?

Thanks,
Richard
Coordinator
Jan 29, 2014 at 12:36 AM
Edited Feb 1, 2014 at 8:39 PM
Hi Richard,

LINQ to LDAP doesn't have the ability to translate that into a sub-query (which is how SQL would treat it) since LDAP doesn't really have that capability. An alternative is to turn that into an Or Equal operation. The simplest solution is to use the Filter class:
var users = context.Query<User>().Any(u => Filter.EqualAny(u, _ => u.Groups, groups, false));