applicationDbContext.Database .ExecutesqlCommand(@"ALTER DATABASE CURRENT SET RECOVERY FULL;");
ALTER DATABASE statement not allowed within multi-statement
transaction.@H_301_5@
我已经解决了一个TransactalBehavior的问题,如下面的代码:@H_301_5@
applicationDbContext.Database.ExecutesqlCommand( TransactionalBehavior.DoNotEnsureTransaction,@"ALTER DATABASE CURRENT SET RECOVERY FULL;");
我的问题:@H_301_5@
为什么我会收到这个错误与EF 6?
>我的修复是一个有效的修复问题或一个恶魔隐藏在这个解决方案后面?
>还有其他办法解决问题吗?@H_301_5@
任何帮助将不胜感激!?@H_301_5@
解决方法
Starting with Entity Framework 6.0,ExecutesqlCommand() by default will wrap the command in a transaction if one was not already present. There are overloads of this method that allow you to override this behavior if you wish.@H_301_5@
EF 5的行为方式不一样.你的修复是适当的@H_301_5@
You can now specify a TransactionalBehavior flag to instruct EF on how to handle transactions with this command.@H_301_5@
var sqlCommand = String.Format("ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE"); db.Database.ExecutesqlCommand(TransactionalBehavior.DoNotEnsureTransaction,sqlCommand);
通过使用DoNotEnsureTransaction标志,在执行命令之前,EF不会启动事务.这样可以使ALTER DATABASE命令成功执行.@H_301_5@
http://www.danbartram.com/entity-framework-6-and-executesqlcommand/@H_301_5@