Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

c# - Azure Active Directory Graph Client 2.0 - Context is not currently tracking the entity

I have recently installed the Azure Active Directory Graph Client Library 2.0.2 Nuget package and am unable to add Members to Groups both adding a group to a group or adding a user to a group I am getting the following error when the AddLink function is called:

“[System.InvalidOperationException] = {"The context is not currently tracking the entity."}

My code:

IGroup group = azureClient.Groups.GetByObjectId("Guid here").ExecuteAsync().Result;
IGroup groupToAdd = azureClient.Groups.GetByObjectId("Guid here").ExecuteAsync().Result;
azureClient.Context.AddLink(group, "Members", groupToAdd);
azureClient.Context.SaveChanges();

I have been unable to find any mention of this error in relation to the Azure Active Directory Graph Client Library from doing Google searches so any help on this would be much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

We’ve just released an update to the Graph client library, that fixes this problem. You should now be able to add members to groups. The mechanism is a little different from using AddLinks (and hopefully simpler).

We also have a new blog describing the client library which talks about this and many other things: http://blogs.msdn.com/b/aadgraphteam/archive/2014/12/12/announcing-azure-ad-graph-api-client-library-2-0.aspx

For reference, to add a member to a group:

{groupObject}.Members.Add({entityObject} as DirectoryObject);

So for example, to update a group with a new user member:

myGroup.Members.Add(userToBeAdded as DirectoryObject); await myGroup.UpdateAsync();

NOTE: The same construct can be used to add users to a DirectoryRole object. Groups and users may be added to a group, however, for now, only users can be added to a DirectoryRole.

Hope this helps,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...