如何使用 LINQ 使用 Azure AD Graph API Client Library 2.0 查找具有特定许可证的 Azure AD 用户
How can you use LINQ to find Azure AD users with specific licenses using the Azure AD Graph API Client Library 2.0
我从开始工作的 sample .NET Graph API Console app 开始。我希望能够为所有具有特定许可证的用户查询 Azure AD。我想我必须做某种嵌套的 LINQ 查询。
这是我的第一次尝试
IUserCollection userCollection = activeDirectoryClient.Users;
searchResults = userCollection.Where(user =>
user.AssignedPlans.Where(plans => plans.Service.Contains("exchange")) &&
user.DisplayName.StartsWith(searchString)).ExecuteAsync().Result;
usersList = searchResults.CurrentPage.ToList();
我收到一条错误消息 "Error 3 Operator '&&' cannot be applied to operands of type 'System.Collections.Generic.IEnumerable' and 'bool"
我尝试将 .Where 更改为 .Any 并编译它。
searchResults = userCollection.Where(user =>
user.AssignedPlans.Any(plans => plans.Service.Contains("exchange")) &&
user.DisplayName.StartsWith(searchString)).ExecuteAsync().Result;
但是当我 运行 代码时,我在控制台中收到此错误。
Error getting User Expression of type 'System.Collections.Generic.IList`1[Microsoft.Azure.ActiveDirectory.GraphClient.Internal.AssignedPlan]' cannot be used for
parameter of type 'System.Collections.Generic.IEnumerable`1[Microsoft.Azure.ActiveDirectory.GraphClient.AssignedPlan]' of method 'Boolean Any[AssignedPlan](Sys
tem.Collections.Generic.IEnumerable`1[Microsoft.Azure.ActiveDirectory.GraphClient.AssignedPlan], System.Func`2[Microsoft.Azure.ActiveDirectory.GraphClient.Assig
nedPlan,System.Boolean])'
用户可以有多个分配的计划。我需要 return 所有至少拥有一项分配计划且服务等于 "exchange"
的用户
这里发生了一些事情 - 恐怕我没有任何合适的答案给你。首先,我们的客户端库不支持您正在尝试的那种构造,但我相信我们很快就会解决这个问题。一个更大的问题是我们的服务端不支持查询多值复杂类型(在本例中为 AssignedPlan)。我将提交此项目的功能请求。
我们目前可用的唯一解决方法是您尝试使用我们今天支持的任何方法(请参阅 http://blogs.msdn.com/b/aadgraphteam/archive/2014/02/11/support-for-disjunctive-or-filter-clauses-in-the-graph-directory-service.aspx 或通过客户端库的等效方法)过滤结果集,然后执行客户端过滤器。不理想...
我们认为可能有帮助的另一件事是,如果我们提供 Any(*) 过滤器,它允许您对设置的 属性 进行过滤。这样您就可以过滤到那些已分配计划的用户,然后从那里开始。
告诉我你的想法
我从开始工作的 sample .NET Graph API Console app 开始。我希望能够为所有具有特定许可证的用户查询 Azure AD。我想我必须做某种嵌套的 LINQ 查询。
这是我的第一次尝试
IUserCollection userCollection = activeDirectoryClient.Users;
searchResults = userCollection.Where(user =>
user.AssignedPlans.Where(plans => plans.Service.Contains("exchange")) &&
user.DisplayName.StartsWith(searchString)).ExecuteAsync().Result;
usersList = searchResults.CurrentPage.ToList();
我收到一条错误消息 "Error 3 Operator '&&' cannot be applied to operands of type 'System.Collections.Generic.IEnumerable' and 'bool"
我尝试将 .Where 更改为 .Any 并编译它。
searchResults = userCollection.Where(user =>
user.AssignedPlans.Any(plans => plans.Service.Contains("exchange")) &&
user.DisplayName.StartsWith(searchString)).ExecuteAsync().Result;
但是当我 运行 代码时,我在控制台中收到此错误。
Error getting User Expression of type 'System.Collections.Generic.IList`1[Microsoft.Azure.ActiveDirectory.GraphClient.Internal.AssignedPlan]' cannot be used for
parameter of type 'System.Collections.Generic.IEnumerable`1[Microsoft.Azure.ActiveDirectory.GraphClient.AssignedPlan]' of method 'Boolean Any[AssignedPlan](Sys
tem.Collections.Generic.IEnumerable`1[Microsoft.Azure.ActiveDirectory.GraphClient.AssignedPlan], System.Func`2[Microsoft.Azure.ActiveDirectory.GraphClient.Assig
nedPlan,System.Boolean])'
用户可以有多个分配的计划。我需要 return 所有至少拥有一项分配计划且服务等于 "exchange"
的用户这里发生了一些事情 - 恐怕我没有任何合适的答案给你。首先,我们的客户端库不支持您正在尝试的那种构造,但我相信我们很快就会解决这个问题。一个更大的问题是我们的服务端不支持查询多值复杂类型(在本例中为 AssignedPlan)。我将提交此项目的功能请求。
我们目前可用的唯一解决方法是您尝试使用我们今天支持的任何方法(请参阅 http://blogs.msdn.com/b/aadgraphteam/archive/2014/02/11/support-for-disjunctive-or-filter-clauses-in-the-graph-directory-service.aspx 或通过客户端库的等效方法)过滤结果集,然后执行客户端过滤器。不理想...
我们认为可能有帮助的另一件事是,如果我们提供 Any(*) 过滤器,它允许您对设置的 属性 进行过滤。这样您就可以过滤到那些已分配计划的用户,然后从那里开始。
告诉我你的想法