I am working on Azure B2C single Signon. I am using:
Microsoft.Azure.ActiveDirectory.GraphClient;
I want to create a function to assign a user to a group, but it is not working:
var user = this.aadClient.Users.Where(u => u.SignInNames.Any(n => n.Value == "sss@sss.com"))
.ExecuteAsync().Result.CurrentPage.FirstOrDefault() as User;
var group = this.aadClient.Groups.Where(x => x.DisplayName.Equals(role, StringComparison.OrdinalIgnoreCase))
.Expand(g => g.Members).ExecuteAsync().Result.CurrentPage.FirstOrDefault() as Group;
group.Members.Add(user);
await group.UpdateAsync();
both the user and the group are correct. But I am getting this exception on await group.UpdateAsync():
The relationship is already tracked by the context.
I have tried to update the context:
await this.aadClient.Context.SaveChangesAsync();
But I am getting the same exception.
Where is the problem in my Code? Any tips could be helpful. thank you!