简体   繁体   English

C#上下文已经在跟踪实体,蔚蓝的活动目录图api。 添加组成员

[英]C# context is already tracking the entity, azure active directory graph api. add group member

I am trying to add member to azure active directory group but it fails it showing me following error. 我正在尝试将成员添加到azure活动目录组中,但是它无法通过它显示以下错误。

context is already tracking the entity 上下文已经在跟踪实体

I tried to found lot for it, I also see this links 我试图找到很多东西,我也看到了这个链接

Azure Active Directory Graph Client 2.0 - Context is not currently tracking the entity Azure Active Directory Graph Client 2.0-上下文当前未跟踪实体

http://blogs.msdn.com/b/aadgraphteam/archive/2014/12/12/announcing-azure-ad-graph-api-client-library-2-0.aspx http://blogs.msdn.com/b/aadgraphteam/archive/2014/12/12/announcing-azure-ad-graph-api-client-library-2-0.aspx

But I not get any success please help me. 但是我没有任何成功,请帮助我。

This is my code : 这是我的代码:

try
        {
            ActiveDirectoryClient client = ADGraphHelper.GetActiveDirectoryClient();
            IGroupFetcher groupFetcher = client.Groups.GetByObjectId(groupId);
            Group group = (Group)(await groupFetcher.ExecuteAsync());
            string[] userIds = userId.Split(',');
            foreach (string id in userIds)
            {
                if (id != "")
                {
                    IUser user = client.Users.Where(u => u.ObjectId == id).ExecuteAsync().Result.CurrentPage.ToArray().First();
                    if (user != null)
                    {
                        //check wather user aleady present into group or not
                        IDirectoryObject userExists = group.Members.Where(u => u.ObjectId == id).FirstOrDefault();
                        if (userExists == null)
                        {
                            group.Members.Add(user as DirectoryObject);
                        }
                    }
                    else
                        throw new Exception("User is null.");
                }
            }
            await group.UpdateAsync();
            return Json(new { success = true });
        }
        catch (Exception ex)
        {
            ModelState.AddModelError("", "we connot process your request please contact to support for more details.");
// error handling code.
            return PartialView();
        }

Hey everyone I found what is issue now in this. 大家好,我发现了现在的问题所在。 it was the bug on the old Graph client library. 这是旧Graph客户端库上的错误。 it is solved in the Graph client library 2.0, So please use Graph client library 2.0 or higher. 它是在Graph客户端库2.0中解决的,因此请使用Graph客户端库2.0或更高版本。

This is the link where you can download latest graph client library: https://www.nuget.org/packages/Microsoft.Azure.ActiveDirectory.GraphClient/ 这是您可以下载最新图形客户端库的链接: https : //www.nuget.org/packages/Microsoft.Azure.ActiveDirectory.GraphClient/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM