0

I'm using LinqToLdap. I've been successful to search users from within one namingContext (ie, this is a particular OU within the AD). What I want to do is add another namingContext and be able to query both of them at once.

Do you know how I can achieve this?

I've done the following but with no success - it always searches against the first Mapping.

var config = new LdapConfiguration();


config.AddMapping(new UserMap1(), "namingContext1 - OU etc etc");
config.AddMapping(new UserMap2(), "namingContext2 - OU etc etc");

public class UserMap1: ClassMap<User>
public class UserMap2: ClassMap<User>

My query is as follows -

using (var context = new LinqToLdap.DirectoryContext(conn, true, config))
            {

                var query =
                    context.Query<User>()
                        .Where(x => searchTextAsArray.Contains(x.GivenName) || searchTextAsArray.Contains(x.Sn))
                        .Select(u => new
                        {
                            u.GivenName,
                            u.Sn,
                            u.DistinguishedName,
                            u.Cn,
                            u.UserPrincipalName,
                            Score = (searchTextAsArray.Contains(u.GivenName) ? 1 : 0) + (searchTextAsArray.Contains(u.Sn) ? 1 : 0)
                        }).ToList();


                var results = query.OrderByDescending(u => u.Score).ThenBy(u => u.Sn).ThenBy(u => u.GivenName);


                foreach (var result in results)
                {
                    Console.WriteLine("{0} {1} - {2}",
                        result.GivenName,
                        result.Sn,
                        result.Score);
                }

            }

It only takes into account the first mapping...

Any help would be great.

dotnethaggis
  • 1,000
  • 12
  • 26

1 Answers1

0

LDAP is directory based. You'll have to move to a higher shared node or issue two separate queries.

Alan
  • 456
  • 2
  • 9