views:

68

answers:

1

The ASP.NET linq SubmitChanges method commits changes for all previous database modifications since the last time it was called.

I have a case where I do something like the following:

ClassX x = new Abc.Linq.ClassX();
DataContext.InsertOnSubmit(x);

ClassY y = new Abc.Linq.ClassXY();
DataContext.InsertOnSubmit(y);

DataContext.SubmitChanges();//x and y are committed to the database

I would like to insert y but not X in the line above. Then I would like to insert X with another call to SubmitChanges() sometime later. I have to execute the code in the order shown.

Is that possible? Or should I be calling something other than SubmitChanges()?

+4  A: 

I would use separate DataContexts for this. The DataContext is simply a wrapper for data access, and a set of pending changes. It does not support partial commits of its changelist. InsertOnSubmit does what it says it does - is there a reason you need to call that before you actually want it submitted? Perhaps if you elaborated on the problem that's locking you into this execution order we could provide a better solution.

JoshJordan
+1 for separate DataContexts, given this particular scenario.
keyboardP