Hi CJBriers - You may be right that the parent entity should be marked as having changed if one of its child entities changes ...
in your scenario.
For example, I favor your business logic with respect to an Order and its OrderDetails; any change to an Order's details ... including add or deleting a detail ... is a change to the Order. How do I know this? Because I know about the
business rules that govern the relationship between Orders and their details; an order is substantially defined by its details.
Consider instead the relationship between a Customer and its Orders. Should a change to any order ... or the addition / deletion of an order ... constitute a change to the Customer who placed the order? One cannot say a priori. In most systems, the Customer would NOT be changed.
So you have two structurally identical parent/child relationships - Order/OrderDetail and Customer/Order - with different rules for modifying the parent when a child changes. Structure alone does not tell us what to do. DevForce takes the parsimonious approach and doesn't touch the parent. We leave it to the developer to decide what to do ... and implement that decision.
I have long felt that we should make it easy for the developer to express a parent-update rule declaratively and have DevForce enforce it. We don't have that feature at this time ... and you won't find it in similar systems either because the implementation is not necessarily as obvious as it first seems. One must, for example, decide what to do when the parent Order is not in cache ... and what to do when the developer calls "UnDo" on the order or any of its details.
You are welcome to implement the logic that suits your purpose. There are hooks to facilitate. Some popular approaches - often combined:
- add OrderDetail PropertyChanged event handler that calls the parent Order.EntityAspect.SetModified().
- use EntityManager.Saving event handler to ensure that the parent of every OrderDetail about to be saved is also in cache and listed among the entities to be saved; for each missing parent Order, get it, set it "Modified" and add it to the list of entities to be saved. p.s..: unless you have concurrency turned on, Entity Framework won't actually save the Order to the database because it won't see any actual change to the Order data.
You will have to think through what it means to undo changes either to parent orders or their children.
More could be said about the subject. For now I hope this explains why we do what we do and gets you thinking about what you will do.
Edited by WardBell - 26-Jul-2011 at 2:16pm