私は、バスケットにアイテムを追加できるエンドポイント(ASP.NET WebAPI + Entity Framework 6)を持っています。それは次のようになります。バスケットItem with TransactionScope.ReadCommittedまだ複製を作成中
public int AddToBasket(BasketUpdate update) { var transactionOptions = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }; using (var scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions)) { var existingBasketItem = basketItems.Query().FirstOrDefault(item => item.UserId == update.UserId && item.AccountId == update.AccountId && item.ProductId == update.ProductId);
existingBasketItem = existingBasketItem ?? basketItems.Create();
existingBasketItem.Quantity += update.Quantity;
existingBasketItem.AccountId = update.AccountId;
existingBasketItem.UserId = update.UserId;
existingBasketItem.ProductId = update.ProductId;
unitOfWork.Commit();
scope.Complete();
return existingBasketItem.Quantity;
}
}
だから、私はこのエンドポイントへの複数の呼び出しを発射すれば、私は常に合算データベース内の1つのエントリで終わることを(私の無限の降誕に)仮定しましたすべての呼び出しの量が正しくこのエンドポイントをFiddlerに浸透させることは、すべての要求が前回の処理が完了するまで待っていることを確認しているようです。すぐに私が探して停止(または他の誰かがバスケットに項目を追加します)しかし
、私はそのような何かを持っ終わる:
Id Quantity ProductId UserId AccountId
429 12 4560 56 2234
430 1 4560 56 2234
それがどのように地球上で起こることができますか?何らかの点でIISサーバー上に2つのインスタンスが存続する可能性がありますか、ここでのトランザクションについて何か誤解していますか?私の髪を引っ張っているので、助けていただければ幸いです。