LINQ to SQL-确实,SubmitChanges()自动启动事务吗? [英] LINQ to SQL - Is it true that SubmitChanges() automatically starts a transaction?

查看:92
本文介绍了LINQ to SQL-确实,SubmitChanges()自动启动事务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将事务与LINQ to SQL一起使用,我正在阅读以熟悉它.

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

确实已处理SubmitChanges吗?

Is it true that SubmitChanges is already transactioned?

推荐答案

当您调用SubmitChanges时,LINQ to SQL将检查一组已知对象,以确定是否已将新实例附加到这些对象.如果有,则将这些新实例添加到跟踪对象集.

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.

在传输任何实际更改之前,立即 LINQ to SQL启动事务以封装一系列单独的命令.

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

对对象的更改将一一转换为SQL命令,然后发送到服务器.

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.

有关此视图的更多信息,请参见 MSDN文章.

For more info on this view the MSDN article.

希望这会有所帮助!

这篇关于LINQ to SQL-确实,SubmitChanges()自动启动事务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆