zzzprojects / GraphDiff

GraphDiff is a library that allows the automatic update of a detached graph using Entity Framework code first.
https://entityframework-graphdiff.net/overview
MIT License
333 stars 101 forks source link

Nested many to many duplicating entries/ is it possible? #147

Open dmlavigne1 opened 9 years ago

dmlavigne1 commented 9 years ago

I have the following structure: ParentCompany - Id, Name ChildCompany - Id, Name Employee - Id, Name ParentCompanyChildCompany - Id, ChildCompanyId, ParentCompanyId ChildCompanyEmployee - Id, ChildCompanyId, EmployeeId

My goal in a POC is to grab all the ParentCompanies, Child Companies, and Employees. Add a Child Company to a parent by adding a new ParentCompanyChildCompany , then add an employee to the child company by adding a new ChildCompanyEmployee.
I am also trying to modify the name property of all of the entities with the date to prove I can update all the individual entities.

Into the save, I am passing (1) Modified Parent Company --(1) Added ParentCompanyChildCompany ----(1) Modified Child Company (same as in the ParentCompanyChildCompany) ------(1) Added ChildCompanyEmployee --------(1) Modified Employee (same as in the ChildCompanyEmployee)

_entities.UpdateGraph(parentCompany, map => map.OwnedCollection(p => p.ParentCompanyChildCompanies)); _entities.SaveChanges(); **This modifies the parent company, and adds the ParentCompanyChildCompany, does not modify the child, employee etc.

_entities.UpdateGraph(parentCompany, map => map.OwnedCollection(p => p.ParentCompanyChildCompanies, with => with.OwnedEntity(p => p.ChildCompany, withChildren => withChildren.OwnedCollection(p => p.ChildCompanyEmployees, withEmployees => withEmployees.OwnedEntity(p => p.Employee))))); _entities.SaveChanges(); **This modifies the parent company, and adds the ParentCompanyChildCompany, saves the child company and employee as new entities and reflects that in ParentCompanyChildCompany, and ChildCompanyEmployee.

_entities.UpdateGraph(parentCompany, map => map.OwnedCollection(p => p.ParentCompanyChildCompanies, with => with.OwnedEntity(p => p.ChildCompany, withChildren => withChildren.OwnedCollection(p => p.ChildCompanyEmployees, withEmployees => withEmployees.AssociatedEntity(p => p.Employee))))); _entities.SaveChanges(); **This modifies the parent company, and adds the ParentCompanyChildCompany, saves the child company as new entities and reflects that in ParentCompanyChildCompany, and ChildCompanyEmployee. Employee is not modified and the proper entry for that employee is in ParentCompanyChildCompany.

Is there any way to accomplish what I am looking for?