The transaction has been updated, but also to download a new version, compatible with the previous version, expanded the Dbtrans method.
More concise than the transaction in section 17 (transaction). As follows
using (DbTrans trans = DbSession.Default.BeginTransaction())
{
trans.Update<Products>(Products._.ProductName, "apple", Products._.ProductID == 1);
trans.Update<Products>(Products._.ProductName, "egg", Products._.ProductID == 2);
trans.Commit();
}
Generated sql:
Text:
UPDATE [Products] SET [ProductName]=@e6b783222bb34b98b56fc3012500a0d5
WHERE [Products].[ProductID] = @bdb38c8f8fab405d93231e1b2f19c1e2
Parameters:
@e6b783222bb34b98b56fc3012500a0d5[String] = apple
@bdb38c8f8fab405d93231e1b2f19c1e2[Int32] = 1
Text:
UPDATE [Products] SET [ProductName]=@4184e5de4ed545d9bf3f0ba9a38ed6fa
WHERE [Products].[ProductID] = @f1da00f3628a43c2a9c66678e71049c7
Parameters:
@4184e5de4ed545d9bf3f0ba9a38ed6fa[String] = egg
@f1da00f3628a43c2a9c66678e71049c7[Int32] = 2
The execution effect is the same.
Try catch is also written in the same way.
DbTrans trans = DbSession.Default.BeginTransaction();
try
{
trans.Update<Products>(Products._.ProductName, "apple", Products._.ProductID == 1);
trans.Update<Products>(Products._.ProductName, "egg", Products._.ProductID == 2);
trans.Commit();
}
catch
{
trans.Rollback();
}
finally
{
trans.Close();
}
A transaction in a component is not a distributed transaction, but a simple transaction encapsulation.