views:

638

answers:

2

I am running the code to get the change set just before a linq submit changes call.

private void OnSubmitHandleReplication()
{
    System.Data.Linq.ChangeSet changes = GetChangeSet();
    //Do something with change set
}

In the do something section I need to know what order things were submitted in, and what order they will post to the database in. I see the change set has a .Inserted, .Updated, and .Deleted. I assume that these are in the order they will be applied in. However I want to know the over all order. I assume it could be Insert, Update, then 3 more inserts, or something that involves bounce back and forth between these collections.

Update 1

Sorry, thought the title was clear, Linq to SQL

Update 2

The reason I am doing this is to replay these later to another DB.

A: 

This is quite tricky.

You would need to dig quite far into the change tracker with reflection to get the actual order.

Regarding the order of insert, update, delete, inserts happen before delete, so you need to watch out for unique constraints (which probably means you needed to update instead of recreate).

EDIT

If you just need to 'replay', surely you could use the logging feature.

leppie
Could you expand on the logging feature?
Anthony D
A: 

You can enable logging in Linq2SQL by setting YourDataContext.Log = Console.Out or to any other compatible output stream. Every SQL query LINQ is sending to the database will be printed there. You should only use this for debugging your problem, because LINQ sends quite a lot of queries :)

Edit: Regarding the order of the actions, I cannot help you any further, I never looked at these queries more than I had to.

Olli