重要なトランザクションを処理するアクションがあり、トランザクションを処理する最善の方法がわかりません。
これは私がしなければならないことの簡単な例です:
[HttpPost]
public ActionResult BeginOrderProcess(Guid orderKey)
{
// Not sure what isolation level I sould use here to start with...
IsolationLevel isolationLevel = IsolationLevel.ReadCommitted;
using(new TransactionScope(isolationLevel)){
// Retreive the order
var order = GetExistingOrder(orderKey);
// Validate that the order can be processed
var validationResult = ValidateOrder(order);
if (!validationResult.Successful)
{
// Order cannot be processed, returning
return View("ErrorOpeningOrder");
}
// Important stuff going on here, but I must be sure it
// will never be called twice for the same order
BeginOrderProcess(order);
return View("OrderedProcessedSuccessfully");
}
}
最初に質問したいのは、この種の操作では、同じ注文に対して同時に複数のリクエストを行うことができる場合 (つまり、同じ注文に対するブラウザーからのクイック リクエスト)、悲観的ロックを使用して 1 つのトランザクションを実際に保証する必要があるかどうかです。時間またはBeginOrderProcess
楽観的ロックを使用してほぼ同時に同じ注文に対する2つの同時リクエストで2回呼び出されないようにする方法があります(おそらくより高速になると考えられます)?
第二に、私はそれを完全に間違った方法で行っていますか?このようなケースを処理するためのより良い方法はありますか? 言い換えれば、これをどのように処理すればよいですか?:)