views:

49

answers:

1

I have a program in which I am performing non-atomic updates to the database with a single DataContext (that is, the changes are submitted when the user clicks Save, not after each transaction).

When the user saves, I would like to be able to query the database (as it would be when I call submitChanges()) and do some checks just before I call submitChanges(). Is there a way to get this 'preview'?

(Calling getChangeSet() in this instance makes things very complex.)

Any ideas?

+2  A: 

Why can't you just use a transaction? If you explicitly set a Transaction on the DataContext, then SubmitChanges won't begin/commit its own transaction. It will rely on you committing the explicit transaction. As long as you're still in the active transaction, SQL will act as if the changes are committed and then you can choose to commit or roll back as needed.

Look into SqlConnection.BeginTransaction and SqlTransaction.Commit.

Josh Einstein