c# - Entity Framework 中没有事务的存储过程

标签 c# entity-framework transactions transactionscope

我在 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/

相关文章:

mysql - Codeigniter 中具有多个表的事务

postgresql - Postgres如何支持没有撤销日志的回滚

c# - 关于处理 DataContext 和 DataBind()

c# - Entity Framework 从 saveChanges 中的上下文获取用户

javascript - 带有反斜杠的 JSON 解析错误

entity-framework - Entity Framework "The underlying provider failed on Open"- Cassini 与 IIS

c# - 我如何结合查询这些数据

google-analytics - Google Analytics(分析)中的产品收入与收入

C# 将图像写入 ziarchive

c# - HTTPS 容易受到 CSRF 攻击吗?