Question

I'm trying to retrieve a set of records from Active Directory using Query by Example. This snippet will find any records with the name of "John Smith":

 PrincipalContext context = new PrincipalContext(ContextType.Domain, contextName);
 User filter = new User(context);
 var users = new List<User>();            
 filter.LastName = "Smith";
 filter.GivenName = "John";
 PrincipalSearchResult<Principal> matches = null;            
 PrincipalSearcher searcher = new PrincipalSearcher(filter);
 matches = searcher.FindAll() as PrincipalSearchResult<Principal>;

but I want to apply these filters so I can match any record with a last name of "Smith" or a given name of "John", e.g. "Mary Smith", "John Brown". Is this possible using Query by Example - without having to run multiple searches? I haven't been able to find any documented examples.

Était-ce utile?

La solution

You can't do any type of OR searching with QBE (Query by Example).

You can write an LDAP query with all the OR's and AND's you want, run that query separately, get back the distinguished names, and then look up all the matching UserContext objects... I know, it sucks.

There are a lot of areas where not much consideration was given when the AccountManagement structure was put together.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top