c# TransactionScope 没有回滚
c# TransactionScope didnt roll back
我是 C# 的新手,正在尝试 TransactionScope 的工作原理。这是我的代码,我想知道为什么我的交易没有回滚:
string file1 = "txf1.txt";
string file2 = "txf2.txt";
using (StreamWriter sw = File.CreateText(file1))
{
sw.WriteLine("Hello World");
}
using (StreamWriter sw = File.CreateText(file2))
{
sw.WriteLine("Hello World");
}
using (TransactionScope scope = new TransactionScope())
{
File.AppendAllText(file1, "Transaktion");
scope.Complete();
}
using (TransactionScope scope = new TransactionScope())
{
File.AppendAllText(file2, "Transaktion");
//should roll back the file, but doesn't
}
File
中没有事务管理器,它不是 "software transaction"。几乎 100% 的时间 TransactionScope
将与 ADO.NET 或构建在其之上的库结合使用,例如 Entity Framework 或 Dapper。在 MSDN TransactionScope Class.
上查看更多信息
我是 C# 的新手,正在尝试 TransactionScope 的工作原理。这是我的代码,我想知道为什么我的交易没有回滚:
string file1 = "txf1.txt";
string file2 = "txf2.txt";
using (StreamWriter sw = File.CreateText(file1))
{
sw.WriteLine("Hello World");
}
using (StreamWriter sw = File.CreateText(file2))
{
sw.WriteLine("Hello World");
}
using (TransactionScope scope = new TransactionScope())
{
File.AppendAllText(file1, "Transaktion");
scope.Complete();
}
using (TransactionScope scope = new TransactionScope())
{
File.AppendAllText(file2, "Transaktion");
//should roll back the file, but doesn't
}
File
中没有事务管理器,它不是 "software transaction"。几乎 100% 的时间 TransactionScope
将与 ADO.NET 或构建在其之上的库结合使用,例如 Entity Framework 或 Dapper。在 MSDN TransactionScope Class.