由于我想查询Active的自定义属性"costCenter“,所以我使用了一个自定义UserPrincipalEx类。因此,自定义UserPrincipalEx Class添加了DirectoryProperty("costCenter")。基本和长时间运行的(3分钟)版本如下所示:
// create domain context
PrincipalContext context = new PrincipalContext(ContextType.Domain, "myDomainController");
// define the query-by-example principal
UserPrincipal qbeUser = new UserPrincipal(context);
// create the principal searcher
PrincipalSearcher searcher = new PrincipalSearcher(qbeUser);
// find all matches
foreach (var hit in searcher.FindAll())
{
//do incredible stuff here
}现在,使用为自定义属性"UserPrincipalEx“扩展的自定义类"costCenter":
UserPrincipalEx qbeUser = new UserPrincipalEx(context);
qbeUser.costCenter = "123";使得查询的执行速度几乎和轻型一样快。但是,我真正需要的是查询所有只有costCenter的用户(并非所有用户都这样做)。
因此,我的问题是:如何使用扩展的“逐例查询”主体搜索只有有的自定义属性?。
发布于 2013-09-26 07:30:29
我重新使用了
Parallel.ForEach 为了加快整件事的进度。ForEach-循环运行在一个具有我感兴趣的自定义属性的所有值的IEnumerable上,用这些值中的一个来擦亮UserPrincipalEx属性,并将结果添加到列表中。
不完全是我想要的,但有效:从3分钟到15秒。
https://stackoverflow.com/questions/19012734
复制相似问题