I using Entity Framework 4 and meet following issue whith executing stored procedure in ambient transaction. Here is the code:
public void UpdateOrderRequest(IOrder order, int requestId, int userId, Fee fee)
{
using (var tscope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
_storedProcedureDA.UpdateOrderRequest(requestId, userId, data.ClientId, data.RequestStatus, data.Date,
data.Type, data.Side, data.Quantity, data.ExecInst, data.Price,
data.StopPrice, data.TimeInForce, data.Description, data.Target);
var feeDa = new FeeDA();
var dbFee = new Domain.Entities.Fee
{
OrderRequestId = requestId,
Identifier = fee.Id,
Value = fee.Value,
};
feeDa.Save(dbFee);
tscope.Complete();
}
}
- _StoredProceduresDA and FeeDA are data access classes that uses one instance of DataContext for each.
- _storedProcedureDA.UpdateOrderRequest() method is just wrapper under
Context.ExecuteFunction<..>("AddOrderRequest",...)
feeDA.Save()
adds entity into Repository and callsContext.SaveChanges()
- When i trying to make this call, i catching following exception:
The transaction operation cannot be performed because there are pending requests working on this transaction.
The point is that i need to do both of these operations in one transaction and i can't use workaround suggested in Can't I call a stored procedure from Entity Framework inside a transaction scope? (ado.net using its own connection) Does anyone knows how to wrap DataContext.ExecuteFunction<>() in transaction?
P.S. I've tried to wrap ExecuteFunction in its own transaction with its own TransactionScope with all possible parameters(Supress and so on) but hothing helped.