Reputation: 4594
I am trying to get better at my data access patterns, and as such am trying to ensure where needed I am using things with transactions.
I wonder, if I make many changes, across many different Repository Classes (data access classes) and then just call SubmitChanges from one class, will that be safe, even if I have used other classes as part of my transaction.
Is there a good tutorial for best practice linq2sql transactions, and where would I need a more complex solution than the built in transactions of SubmitChanges?
Upvotes: 1
Views: 117
Reputation: 8920
wonder, if I make many changes, across many different Repository Classes (data access classes) and then just call SubmitChanges from one class, will that be safe, even if I have used other classes as part of my transaction.
Yes, that will be safe. As long as you call SubmitChanges once, Linq-2-sql will do all the updates and it will do do so in one transaction that is created for you by linq-2-sql. There is no need to add a separate transaction yourself.
and where would I need a more complex solution than the built in transactions of SubmitChanges?
Well, all I can think of is if you want to update using separate datacontexts, for example accross multiple databases.
Upvotes: 0
Reputation: 2836
All changes to linq to sql objects belonging to the same DataContext will be committed to the database when SubmitChanges() is called, no matter where it's called from.
Upvotes: 2