diff --git a/Apewer.Source/Source/DbClient.cs b/Apewer.Source/Source/DbClient.cs index 594edbb..6e788cc 100644 --- a/Apewer.Source/Source/DbClient.cs +++ b/Apewer.Source/Source/DbClient.cs @@ -131,7 +131,7 @@ namespace Apewer.Source { if (_transaction != null) { - if (_autocommit) Commit(); + if (_auto_commit) Commit(); else Rollback(); _transaction = null; } @@ -155,11 +155,18 @@ namespace Apewer.Source const string TransactionNotFound = "事务不存在。"; private IDbTransaction _transaction = null; - private bool _autocommit = false; + private bool _auto_commit = false; /// 获取已启动的事务。 public virtual IDbTransaction Transaction { get => _transaction; } + /// 设置事务。指定为 NULL 将去除事务。 + public void SetTransaction(IDbTransaction transaction, bool autoCommit = false) + { + _transaction = transaction; + _auto_commit = autoCommit; + } + string Begin(bool commit, Class isolation) { if (_transaction != null) @@ -175,7 +182,7 @@ namespace Apewer.Source try { _transaction = isolation ? _conn.BeginTransaction(isolation.Value) : _conn.BeginTransaction(); - _autocommit = commit; + _auto_commit = commit; return null; } catch (Exception ex) @@ -196,8 +203,8 @@ namespace Apewer.Source /// Snapshot
通过在一个应用程序正在修改数据时存储另一个应用程序可以读取的相同数据版本来减少阻止。 表示您无法从一个事务中看到在其他事务中进行的更改,即便重新查询也是如此。
/// Unspecified = -1
正在使用与指定隔离级别不同的隔离级别,但是无法确定该级别。
/// - /// 在连接的生命周期结束时未结束事务,指定 TRUE 将自动提交,指定 FALSE 将自动回滚。 - public virtual string Begin(bool commit = false) => Begin(commit, null); + /// 在连接的生命周期结束时未结束事务,指定 TRUE 将自动提交,指定 FALSE 将自动回滚。 + public virtual string Begin(bool autoCommit = false) => Begin(autoCommit, null); /// /// 使用指定的事务锁定行为启动事务。 @@ -209,9 +216,9 @@ namespace Apewer.Source /// Snapshot
通过在一个应用程序正在修改数据时存储另一个应用程序可以读取的相同数据版本来减少阻止。 表示您无法从一个事务中看到在其他事务中进行的更改,即便重新查询也是如此。
/// Unspecified = -1
正在使用与指定隔离级别不同的隔离级别,但是无法确定该级别。
///
- /// 在连接的生命周期结束时未结束事务,指定 TRUE 将自动提交,指定 FALSE 将自动回滚。 + /// 在连接的生命周期结束时未结束事务,指定 TRUE 将自动提交,指定 FALSE 将自动回滚。 /// 指定事务锁定行为,不指定时将使用默认值。 - public virtual string Begin(bool commit, IsolationLevel isolation) => Begin(commit, new Class(isolation)); + public virtual string Begin(IsolationLevel isolation, bool autoCommit = false) => Begin(autoCommit, new Class(isolation)); /// 提交事务。 public virtual string Commit() diff --git a/Apewer/Source/IDbAdo.cs b/Apewer/Source/IDbAdo.cs index 00ae508..cd570c9 100644 --- a/Apewer/Source/IDbAdo.cs +++ b/Apewer/Source/IDbAdo.cs @@ -62,6 +62,9 @@ namespace Apewer.Source /// 获取已启动的事务。 IDbTransaction Transaction { get; } + /// 设置事务。指定为 NULL 将去除事务。 + void SetTransaction(IDbTransaction transaction, bool autoCommit = false); + /// /// 使用默认的事务锁定行为启动事务。 /// Chaos
无法覆盖隔离级别更高的事务中的挂起的更改。
@@ -72,8 +75,8 @@ namespace Apewer.Source /// Snapshot
通过在一个应用程序正在修改数据时存储另一个应用程序可以读取的相同数据版本来减少阻止。 表示您无法从一个事务中看到在其他事务中进行的更改,即便重新查询也是如此。
/// Unspecified = -1
正在使用与指定隔离级别不同的隔离级别,但是无法确定该级别。
///
- /// 在连接的生命周期结束时未结束事务,指定 TRUE 将自动提交,指定 FALSE 将自动回滚。 - string Begin(bool commit = false); + /// 在连接的生命周期结束时未结束事务,指定 TRUE 将自动提交,指定 FALSE 将自动回滚。 + string Begin(bool autoCommit = false); /// /// 使用指定的事务锁定行为启动事务。 @@ -85,9 +88,9 @@ namespace Apewer.Source /// Snapshot
通过在一个应用程序正在修改数据时存储另一个应用程序可以读取的相同数据版本来减少阻止。 表示您无法从一个事务中看到在其他事务中进行的更改,即便重新查询也是如此。
/// Unspecified = -1
正在使用与指定隔离级别不同的隔离级别,但是无法确定该级别。
///
- /// 在连接的生命周期结束时未结束事务,指定 TRUE 将自动提交,指定 FALSE 将自动回滚。 + /// 在连接的生命周期结束时未结束事务,指定 TRUE 将自动提交,指定 FALSE 将自动回滚。 /// 指定事务锁定行为,不指定时将使用默认值。 - string Begin(bool commit, IsolationLevel isolation); + string Begin(IsolationLevel isolation, bool autoCommit = false); /// 提交事务。 /// 异常常见于事务已经提交或连接已断开。