1

我有一些代碼拋出異常,當我在TransactionScope中使用SqlServer CE 4.0 &。首先是代碼,然後是錯誤。嘗試使用EF CTP5&SqlServerCE4.0 ==進行簡單事務失敗。爲什麼?

// Arrange. 
// ... some stuff ... 
// like .. order = get order with ID #1. 

// Act. 
using (new TransactionScope()) 
{ 
    order.Name = name; // Update a field. 
    _orderRepository.Save(order); 
    _unitOfWork.Commit(); // <-- this works 100% fine. 

    // Assert. 
    // Reload the order so we can see if the data persisted to the DB. 
    var updatedOrder = _orderRepository 
    .Find() 
    .Where(x => x.OrderId == 1) 
    .SingleOrDefault(); <-- // this throws the exception. 

    Assert.IsNotNull(updatedOrder); 
    Assert.AreEqual(name, order.Name); 
} 

異常錯誤是: -

System.Data.EntityException:本 基礎提供失敗的打開。 ---> System.InvalidOperationException:連接對象不能被 列入事務範圍。

因此,第一次保存/提交工作正常,但是當我嘗試再次檢索對象(查看數據是否保留在事務中)時發生錯誤。

現在我敢肯定,這是一個單交易而不是分佈式事務 ...所以我假定這應該只是工作?

建議,善良的民間?

+0

SQLCE不支持TransactionScope。使用正常的DB事務。 – leppie 2011-01-23 05:40:52

回答

相關問題