Active Directory にカスタム属性「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
}
ここで、カスタム属性「costCenter」用に拡張されたカスタマイズされたクラス「UserPrincipalEx」を使用します。
UserPrincipalEx qbeUser = new UserPrincipalEx(context);
qbeUser.costCenter = "123";
クエリをほぼ同じ速さで実行します。しかし、私が本当に必要としているのは、costCenterを持っているだけのすべてのユーザーに対してクエリを実行することです (すべてのユーザーがそうしているわけではありません)。
私の質問は次のとおりです: 拡張された「Query-By-Example」プリンシパルを使用して、カスタム属性だけを持つプリンシパルを検索する方法は?