什麼是LINQ經典的交易模式之間的差異,以SQL LIKE:的TransactionScope VS在LINQ交易到SQL
using(var context = Domain.Instance.GetContext())
{
try
{
context.Connection.Open();
context.Transaction = context.Connection.BeginTransaction();
/*code*/
context.Transaction.Commit();
}
catch
{
context.Transaction.Rollback();
}
}
VS的TransactionScope的對象
using (var context = Domain.Instance.GetContext())
using (var scope = new TransactionScope())
{
try
{
/*code*/
scope.Complete();
}
catch
{
}
}
如果您需要提交具有循環屬性(常見)的內容,那麼您會遇到LINQ to SQL中的一個錯誤,該錯誤要求您刪除每個雙向引用的一部分,提交,修復雙向引用並再次提交。您需要將所有這些包裝在自己的交易中才能這樣做。這是一個普遍的需求,所以「不要擔心」不是最好的答案。 – 2011-07-12 14:56:03