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

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

Open
dmlavigne1 opened this issue Sep 15, 2015 · 0 comments
Open

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

dmlavigne1 opened this issue Sep 15, 2015 · 0 comments

Comments

@dmlavigne1
Copy link

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?

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

1 participant