There is a collection of Product objects, each of which contains two collections of User objects and one main Creator user:
public class User { public int Id { get; set; } public string Name { get; set; } } public class Product { public int Id { get; set; } public string Title { get; set; } public User Creator { get; set; } public ICollection<User> UsersAsMain { get; set; } public ICollection<User> UsersAsReserve { get; set; } } - User objects in both lists of the same
Productobject are all different, do not repeat. - A copy (single instance) of a
Creatorobject may be in one of the lists. - User objects that are in the same
Productmay also be in the rest.
You need to go through all users and, if a copy of it is found, assign it a link to the main object. As a result, all the same users must refer to the same object in memory.
How to create a LINQ query (possibly several) to check and redefine links? It is enough to compare by Id .
Creatorobject" is this that you create a separateUserclone and push it into theCreator? Or I do not understand something. - SublihimCreatormay also be present in one of the lists. - tretetexvar user = new User(...)and then insert this user in the lists and in the Creator, then only references to a single object in the memory will be stored there? - Sublihim