Ordering of Commands – What do you think?

Some of our customers write code like this:

ctx.AddToCustomers(customer);
ctx.AddToProducts(product1);
ctx.AddToProducts(product2);

And expect the Entity Framework to issue 3 insert commands in the same order.

Today the EF doesn’t preserve this sort of ordering.

Instead the order inserts/updates and deletes are made in the Entity Framework is based mainly on local inter-dependencies.

For example if you insert a new Product in a new Category we have to add the Category before the Product .

This means that if you have a large set of changes there are local ordering constraints that we must satisfy first, and these rules can easily be in conflict with order things actually happen in the ObjectContext.

For example if you do this:

 ctx.AddToProducts(
   new Product{
      Name = "Bovril",
      Category = new Category {Name = "Food"}
   }
);

the effect is that the Product is added (to the context) first and then when we walk the graph we add the Category too.

i.e. the insert order into the context is:

 Product
Category

but because of referential integrity constraints we must re-order like this before attempting to insert into the database:

 Category
Product

So this kind of local re-ordering is kind of non-negotiable.

However if there are no local dependencies like this, you could in theory preserve the order of changes.

Today though we don't track 'when' something was added to the context or even when something gets modified, and for efficiency reason we don't track entities in order preserving structures like lists. So currently we can't preserve the order of unrelated inserts, updates and deletes etc.

My question to you is how important is this?

Would you like to see us preserve your ordering as much as possible?