开发者

LINQ to SQL - is there a way to get a 'preview' of the database with changes made to a context?

开发者 https://www.devze.com 2022-12-17 02:32 出处:网络
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).

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 开发者_StackOverflow社区this instance makes things very complex.)

Any ideas?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号