我在 Entity Framework 6 中调用一个存储过程,它可以在必要时创建数据库和表。它正在抛出错误;
Message "CREATE DATABASE statement not allowed within multi-statement transaction.\r\nALTER DATABASE statement not allowed within multi-statement transaction.\r\nDatabase 'CoreSnapshotJS3' does not exist. Make sure that the name is entered correctly." string
我不想在交易中使用它,并已使用它来抑制交易
using (var transation = new TransactionScope(TransactionScopeOption.Suppress))
{
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("spCreateSnapshotFromQueue", snapshotQueueIDParameter);
}
它仍然会抛出错误。
如何停止自动交易?
最佳答案
我找到了一个方法:
var snapshotQueueIDParameter = new SqlParameter("SnapshotQueueID", entityId);
return _db.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction,
"EXEC spCreateSnapshotFromQueue @SnapshotQueueID", snapshotQueueIDParameter);
关于c# - Entity Framework 中没有事务的存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25481063/