在C#.Net 2.0中进行事务的最佳实践是什么?应该使用哪些类?需要注意的缺陷是什么等等.所有提交和回滚的东西.我刚刚开始一个项目,我可能需要在将数据插入数据库时进行一些事务.任何有关交易的基本内容的回复或链接都是受欢迎的.
LINQ to SQL中的经典事务模式有什么区别:
using(var context = Domain.Instance.GetContext())
{
try
{
context.Connection.Open();
context.Transaction = context.Connection.BeginTransaction();
/*code*/
context.Transaction.Commit();
}
catch
{
context.Transaction.Rollback();
}
}
Run Code Online (Sandbox Code Playgroud)
vs TransactionScope对象
using (var context = Domain.Instance.GetContext())
using (var scope = new TransactionScope())
{
try
{
/*code*/
scope.Complete();
}
catch
{
}
}
Run Code Online (Sandbox Code Playgroud)