英文:
Retrieving Manager for a list of users from Microsoft Graph
问题
我们使用.NET和最新的Microsoft.Graph NuGet SDK版本5.16来检索Azure Active Directory组的成员。我们需要返回一个包含每个用户的经理(经理的姓名)信息的用户列表。
我们的代码如下所示:
foreach (var groupMember in groupMembers.Value)
{
if (groupMember is User)
{
var u = (User)groupMember;
var manager = await graphClient.Users[u.Id].Manager.GetAsync();
u.Manager = manager;
}
}
问题出在性能上。在特定组中有很多用户,而在添加了几十个用户之后,行u.Manager = manager 的速度变得非常慢。我认为这是因为Microsoft.Graph.Models.User.Manager属性由执行大量更改跟踪的IBackingStore实现支持。无论如何,这是我们无法控制的Microsoft的代码。
除了将User类型封装到POCO中之外,您是否知道解决这个问题的方法?是否有一种方法可以检索一组用户的经理姓名?是否有一种方法可以配置Graph SDK以抑制更改跟踪?
谢谢您的帮助!
英文:
We use .NET and the latest Microsoft.Graph NuGet SDK version 5.16 to retrieve members of an Azure Active Directory group. We need to return back a list of users including information about each user's manager (manager's name).
Our code looks like this:
foreach (var groupMember in groupMembers.Value)
{
if (groupMember is User)
{
var u = (User)groupMember;
var manager = await graphClient.Users[u.Id].Manager.GetAsync();
u.Manager = manager;
}
}
The issue is performance. We have a lot of users in that particular group, and after several dozens of users are added, the line u.Manager = manager slows down to a crawl. I believe this is because the Microsoft.Graph.Models.User.Manager property is backed up by IBackingStore implementation that does a lot of change tracking. Anyways, that's Microsoft's code that we don't control.
Do you know of a way to work around this issue aside from wrapping the User type into a POCO? Is there a way to retrieve the Manager name for a list of users? Is there a way to configure Graph SDK to suppress change tracking?
Thank you for your help!
答案1
得分: 1
不确定如何获取组成员,但当您仅返回组成员的用户时,可以扩展“manager”关系并配置仅返回经理的“displayName”。
var groupMembers = await graphClient.Groups["{group-id}"]
.Members
.GraphUser
.GetAsync((requestConf) =>
{
requestConf.QueryParameters.Expand = new string []{ "manager($select=displayName)" };
});
然后,您可以摆脱foreach (var groupMember in groupMembers.Value)
,因为groupMembers
中的所有用户都将填写Manager
。
英文:
Not sure how you get group members but when you return only users which are members of the group, you can expand manager
relationship and configure only a displayName
of a manager to be returned.
var groupMembers = await graphClient.Groups["{group-id}"]
.Members
.GraphUser
.GetAsync((requestConf) =>
{
requestConf.QueryParameters.Expand = new string []{ "manager($select=displayName)" };
});
Then you can get rid of foreach (var groupMember in groupMembers.Value)
because all users in groupMembers
will have Manager
filled.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论