Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ExecuteSqlCommand in Entity Framework without it being contained in a transaction

I need to execute a stored procedure with Entity Framework.

Normally I call it like this:

this.Context.Database.ExecuteSqlCommand("EXEC edi_UploadTransmission");

However, this particular stored procedure includes accessing a linked server.

Since EF wraps ExecuteSqlCommand in a transaction, it is failing, as a linked server is not supported in a transaction (as far as I can tell).

Is there a way to execute this stored procedure with Entity Framework without it being in a transaction?

like image 844
Greg Gum Avatar asked Apr 13 '16 20:04

Greg Gum


1 Answers

Pass TransactionalBehavior.DoNotEnsureTransaction as the first parameter to the ExecuteSqlCommand method.

For example,

this.Context.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, "EXEC edi_UploadTransmission");
like image 178
Rami A. Avatar answered Sep 20 '22 23:09

Rami A.