Devildog74 wrote:
I have an entity that I create and then hold onto and modify through a series of operations. The entity has a collection of related entities that should be saved diring the final commit.
The parent entity is named User, and the entity collection is named UserRoles. I have a method named AddUserRole. The AddUserRole method is called from various places in code. Each time the AddUserRole method is called, a new UserRoleEntity is added to the UserRoles member of the UserEntity.
So if method A calls AddUserRole and then method B calls AddUserRole, will the insert statements generated during the recursive save operation be executed in the order in which the Releated entities are added to the UserRoles Collection?
If the userrole entities don't have any live relations with other entity objects at that time, then yes, they'll be saved in that order, but that's not defined. I.e.: it can be in that order, but it's not guaranteed. This is because the routine traverses the graph in a recursive manner, i.e.: per node it dives into recursion till the recursion stops and then backtracks till the graph is done, but an entity save is a 3 stage event:
- first save the dependent entities, i.e.: the entities the entity is depending upon,
- then save the entity
- then save all the entities which are depending on the entity to save.
In your situation, user is saved, and in the 3rd phase of that user save, the userrole entities are saved. Each userrole will check if the dependent entity (user) is already saved, yes it is, and it doesn't have any depending entities so the entities will be processed in the order in which they're in in teh entity collection UserRoles.