LINQ to SQL - Is it true that SubmitChanges() automatically starts a transaction?

浪子不回头ぞ 提交于 2019-12-22 01:33:46

问题


I need to use transactions with LINQ to SQL and I was reading around to get familiar with it.

Is it true that SubmitChanges is already transactioned?


回答1:


When you call SubmitChanges, LINQ to SQL examines the set of known objects to determine whether new instances have been attached to them. If they have, these new instances are added to the set of tracked objects.

Immediately before any actual changes are transmitted, LINQ to SQL starts a transaction to encapsulate the series of individual commands.

The changes to the objects are translated one by one to SQL commands and sent to the server.

At this point, any errors detected by the database cause the submission process to stop, and an exception is raised. All changes to the database are rolled back as if no submissions ever occurred.

For more info on this view the MSDN article.

Hope this helps!



来源:https://stackoverflow.com/questions/679870/linq-to-sql-is-it-true-that-submitchanges-automatically-starts-a-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!