Muflix
Muflix

Reputation: 6778

Run SQL without transaction

Is there a way how to execute SQL or stored procedure without creating additional transaction in entity framework ? There is solution for entity framework Stored Procedure without transaction in Entity Framework but it is not available for .net core.

Upvotes: 1

Views: 716

Answers (1)

Ivan Stoev
Ivan Stoev

Reputation: 205589

The default behavior of ExecuteSqlCommand in EF Core is different than the EF6:

Note that this method does not start a transaction. To use this method with a transaction, first call BeginTransaction(DatabaseFacade, IsolationLevel) or UseTransaction(DatabaseFacade, DbTransaction).

Note that the current ExecutionStrategy is not used by this method since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy can be used explicitly, making sure to also use a transaction if the SQL is not idempotent.

In other words, what are you asking is the default behavior in EF Core, so no action is needed.

Upvotes: 1

Related Questions