Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associated Collection reference being update with parent #187

Open
igormpmartins opened this issue Mar 24, 2023 · 0 comments
Open

Associated Collection reference being update with parent #187

igormpmartins opened this issue Mar 24, 2023 · 0 comments
Assignees

Comments

@igormpmartins
Copy link

igormpmartins commented Mar 24, 2023

1. Description

After using UpdateGraph, if an associated collection has an attribute from the same class as the parent node, this attribute ends up being updated with a reference to the parent node.

The scenario is:,

  • User class has an ICollection of Team.
  • Team has a property named CreatedBy (of type User).
  • After using UpdateGraph to add a collection of Teams to a certain user (user.Teams), every Team.CreatedBy is updated with the user that I'm using as parent node.

Here is the code snippet for reproducing the problem:

var user = context.Users.AsNoTracking().FirstOrDefault(q => q.Name == "User_A");
var teams = context.Teams.AsNoTracking().Where(q => q.Name == "Team A").ToList();
user.Teams = teams;
context.UpdateGraph(user, map => map.AssociatedCollection(q => q.Teams));
context.SaveChanges();

So, after using UpdateGraph/SaveChanges, "Team A".CreatedBy receives "User A", although I didn't specify that.

Here are the classes used on this example:

	public class User
	{
		public int Id { get; set; }
		public string Name { get; set; }
		public Boolean IsActive { get; set; }
		public ICollection<Team> Teams {get; set; }
	}
	
	public class Team 
	{
		public int Id { get; set; }
		public string Name { get; set; }
		public User CreatedBy { get; set; }
	}

2. Exception

No exception occurs, just the behavior isn't the expected one.

3. Fiddle

I have a Fiddle that reproduces the problem:
https://dotnetfiddle.net/iaC9MW

4. Any further technical details

The fiddle reproduces the exact same problem that I have on my project.

@JonathanMagnan JonathanMagnan self-assigned this Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants