Reputation: 131
I'm seeking clarity on the behavior of EF Core in regards to child (and grandchild) navigation properties. If I load, with tracking, an object Parent, which has a list of Child objects, who each have a Grandchild object...
If changes are made to the grandchildren, will those records automatically be updated via update(Parent)?
If children are added / removed from the list, will those records automatically be created / deleted via update(Parent)?
When I am initially creating the Parent, will the Children and Grandchildren automatically be created via create(Parent)?
Thank you!
Upvotes: 2
Views: 2866
Reputation: 21646
Navigation properties provide a way to navigate an association between two entity types. Every object can have a navigation property for every relationship in which it participates. We can use it to configure the relationships between two entities.
If changes are made to the grandchildren, will those records automatically be updated via update(Parent)?
Yes, when get the parent entity, you could also get the related entity (children) data, and if update the children's data via update (parent), it will automatically update the children data in the children's data table.
If children are added / removed from the list, will those records automatically be created / deleted via update(Parent)?
When you get the parent entity, if you add items in the to the list, since the children's table doesn't contain the new items, it will auto insert new record in the children's table. For the delete scenario, check the Cascade Delete.
When I am initially creating the Parent, will the Children and Grandchildren automatically be created via create(Parent)?
Yes. You could check the following articles:Saving Related Data
Upvotes: 1