LLBLGen - TransactionScope 或 DataAccessAdapter.StartTransaction
我发现使用 llblgen 管理事务有两个主要选项。
方法 1:
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.StartTransaction(IsolationLevel.ReadCommitted, "TR");
try
{
// ...
adapter.Commit();
}
catch
{
adapter.Rollback();
throw;
}
}
方法 2:
using(TransactionScope scope = new TransactionScope())
{
// ...
scope.Complete();
}
您首选的方法是什么?为什么? (我正在使用适配器/2.6 .net/3.5)
I see there are two main options for managing transactions with llblgen.
Method 1:
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.StartTransaction(IsolationLevel.ReadCommitted, "TR");
try
{
// ...
adapter.Commit();
}
catch
{
adapter.Rollback();
throw;
}
}
Method 2:
using(TransactionScope scope = new TransactionScope())
{
// ...
scope.Complete();
}
What is your prefered method and why? (I'm using adapapter/2.6 .net/3.5)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我倾向于使用 TransactionScope 来管理事务,因为这就是它的设计目的,而 DataAccessAdapter 虽然能够创建事务,但主要是为 DataAccess 设计的。
为了更清楚一点,您可以使用 TransactionScope 来管理跨多个 DataAccessAdapter 的多个事务,而单个 DataAccessAdapter 似乎具有特定的范围。
例如:
另一个注释是 TransactionScope 是线程安全的,而 DataAdapter 则不是。
I would lean towards using TransactionScope for managing transactions as this is what it was designed for whereas the DataAccessAdapter, while it has the ability to create transactions is designed primarily for DataAccess.
To try and be a little clearer, you could use TransactionScope to manage multiple transactions across multiple DataAccessAdapters whilst a single DataAccessAdapter appears to have a specific scope.
For example:
Another side note is that TransactionScope is thread safe, where as DataAdapters are not.