搜索特定邮件地址:不支持方法 "Contains"

Searching for certain mail addresses: The Method "Contains" is not supported

using Microsoft.Azure.ActiveDirectory.GraphClient,我想从 Azure Active Directory 中获取二十个帐户;给出了他们的电子邮件地址。我现在可以向 Azure AD 服务器发送 20 个请求,但与此同时,我的脚本超时了。所以我尝试了一个请求:

public override IEnumerable<IDirectoryEntry> GetEntriesForMails(IEnumerable<MailAddress> emails)
{
    foreach(IUser user in _connection.Client.Users.Where(x => emails.Contains(x.Mail)).FlattenPages())
    {
        yield return new AzureDirectoryEntry(user, this);
    }

这会抛出

的错误

"Contains" is not supported.

是否有另一种受支持的方法可以在一次服务器往返中获取 20 个电子邮件地址的所有用户帐户?

试试代码:

 List<IUser> users = activeDirectoryClient.Users.ExecuteAsync().Result.CurrentPage.ToList();
 List<IUser> user1 = users.Where(u => emails.Any(e => e.Contains(u.Mail))).ToList();

根据 Microsoft 员工的说法,库中没有直接的解决方案。

我们能想到的最佳解决方案是保持客户端查找 table 将电子邮件地址映射到 ObjectId;并定期更新 table(daily/weekly,以及每当查找失败时)。

然后可以在一次调用(GetObjectsByObjectIdsAsync 方法)中从 Azure AD 获取 20 个 ObjectId 的对象。