Entity Framework を使用して次のトランザクションを実行しようとしています。トランザクション スコープ内で、DB からストアド プロシージャを呼び出します。
using (mother_Entities entitiesContext = context.Value)
{
using (var transactionScope = new TransactionScope())
{
// a lot of create, insert, update operations goes here
...
entitiesContext.SaveChanges();
//Execute stored procedure:
var paramMessage = new ObjectParameter("MESSAGE", "");
var paramMotherid = new ObjectParameter("MOTHERID", motherProductId);
var paramTochteridlist = new ObjectParameter("TOCHTER_ID_LIST", string.Join(";", motherIds));
var paramError = new ObjectParameter("ERROR", typeof(int));
var paramErrorText = new ObjectParameter("ERR_TEXT", typeof(string));
entitiesContext.ExecuteFunction("SP_DOCUWARE_UPDATE", paramMessage, paramMotherid,
paramTochteridlist, paramError, paramErrorText);
...
transactionScope.Complete();
}
}
行entitiesContext.ExecuteFunction()
で例外が発生しますTransaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0
私のストアド プロシージャはトランザクションを使用せず、他の関数やプロシージャを呼び出しません。そのため、トランザクション内でストアド プロシージャを実行できない理由がわかりません。
アップデート:
ああ、私はこれをストアドプロシージャで見つけました:
...
IF @COMMIT = 1
BEGIN
IF @CANCEL = 1
ROLLBACK
ELSE
COMMIT
END
ELSE IF @CHECK = 1
ROLLBACK
END
...
コミット例外がスローされた後かもしれません。しかし、このエラーを回避するにはどうすればよいでしょうか?