Entity Framework を使用し、トランザクション スコープ内で単体テストを実行しています。当初、タイトルにエラーが発生していました。
私は何とか問題を切り分けることができました。
using (TransactionScope scope1 = new TransactionScope())
{
using (TransactionScope scope2 = new TransactionScope())
{
// Here there is no code
}
using (Entities se = new Entities())
{
EntityConnection entityConnection = (EntityConnection)se.Connection;
DbConnection storeConnection = entityConnection.StoreConnection;
storeConnection.Open(); // On this line the error occurs
// Some code that runs a stored procedure
}
}
現在発生しているエラーは、「The operation is not valid for the state of the transaction..」です。
トランザクション スコープ 2 を削除すると、すべて正常に動作します。
スコープ 2 をアンビエント トランザクションとしてマークすると、正常に動作します。