2

I have the following structure in the program:

Using transaction As New TransactionScope()

'Make some changes to the data
...

db.SubmitChanges()

'Make some other changes to the data
...

db.SubmitChanges()


transaction.Complete()

End Using

Will the changes be actually saved to the database when each of SubmitChanges() is called, or only transaction.Complete() will physically save them? I mean I don't want the intermediate changes made by 1 user to be visible to others.

SharpAffair
  • 5,558
  • 13
  • 78
  • 158
  • You could try this quickly by breakpointing prior to `transaction.Complete()`. If you did, you'd likely find that anyone trying to access the data you've updated will not get any results until you call `transaction.Complete()` depending on isolation level which is serialised by default I believe. The answer therefore I suspect is by default, no, no user will get intermediate changes, though could depending on [isolation levels](http://msdn.microsoft.com/en-us/library/ms173763.aspx) – Smudge202 Jan 27 '12 at 11:55
  • Check the following link for your answer: http://stackoverflow.com/questions/542525/transactionscope-vs-transaction-in-linq-to-sql – Dhaval Shukla Jan 27 '12 at 12:04
  • You can just call SubmitChanges once at the end of your routine and you will be fine as well. – Pleun Jan 27 '12 at 12:58

1 Answers1

3

SubmitChanges will send the DML statements. Commit will commit the transaction. While the transaction is not committed, other readers will not see your changes. You have no risk of saving partial changes or even making them visible for a shot period of time. You can call SubmitChanges multiple times. Without an explicit transaction SubmitChanges will use one internally.

usr
  • 168,620
  • 35
  • 240
  • 369