我有一个新的.NET 4.0控制台应用程序,它使用:
到目前为止这个工作.我可以很好地添加和读取数据库.
现在,当我添加TransactionScope时,如下例所示:
public static void TestInsert()
{
using (TransactionScope scope = new TransactionScope())
{
using (var context = new MyDbContext())
{
// Create a test user
DateTime dt = DateTime.Now;
var user1 = new User { UserID = 1, UserName = "test" };
context.Users.Add(user1); <-- exception occurs here
context.SaveChanges();
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到错误:
目前不支持在同一事务中具有不同连接字符串的多个同时连接或连接.
似乎即使最新版本的MySql也不喜欢使用EntityFramework的TransactionScope.
我希望能够使用事务,尤其是在测试项目中,以便我可以回滚任何更改.
知道如何解决这个问题或解决它吗?
完整的错误信息
System.Data.DataException was unhandled
Message=An exception occurred while initializing the database. See the InnerException for …Run Code Online (Sandbox Code Playgroud)