我们正在使用Entity Framework并在事务范围内运行单元测试。原本我们会遇到标题中的错误。
我已经成功地部分地解决了这个问题。
我们目前遇到的错误是 "事务状态无效,操作无效"。
如果我删除事务范围2,一切都正常工作。
如果我将范围2标记为环境事务,它也可以正常工作。
我已经成功地部分地解决了这个问题。
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
}
}
我们目前遇到的错误是 "事务状态无效,操作无效"。
如果我删除事务范围2,一切都正常工作。
如果我将范围2标记为环境事务,它也可以正常工作。