Stored procedure without transaction in Entity Framework

I call a stored procedure in Entity Framework 6, which can create databases and tables if necessary. It throws a mistake;

The message "CREATE DATABASE operation is not allowed in a transaction with multiple operations. \ R \ nLTER The DATABASE operator is not allowed in a transaction with multiple operations. \ R \ nThis CoreSnapshotJS3 does not exist. Make sure the name is entered correctly." line

I do not want this in a transaction and used this to suppress a transaction

using (var transation = new TransactionScope(TransactionScopeOption.Suppress)) { return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("spCreateSnapshotFromQueue", snapshotQueueIDParameter); } 

It still causes an error.

How to stop automatic transactions?

+5
source share
1 answer

I found a way:

 var snapshotQueueIDParameter = new SqlParameter("SnapshotQueueID", entityId); return _db.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, "EXEC spCreateSnapshotFromQueue @SnapshotQueueID", snapshotQueueIDParameter); 
+20
source

Source: https://habr.com/ru/post/1201054/


All Articles