optimistic-concurrency

Is there an alternative to ISession.Merge() that doesn't throw when using optimistic locking?

余生长醉 提交于 2019-12-24 11:29:23
问题 I've been trying to use ISession.Merge() to keep coherence between two sessions, but it fails when the merged instance has a higher Version property than the one loaded in the session (with a StaleObjectStateException). Is there an alternative method that would work when the Version fields do not match ? 回答1: Try calling: Session.Lock(string entityName, object obj, LockMode lockMode); with LockMode.Force. The remarks for that method state: This may be used to perform a version check

Dynamo DB Optimistic Locking Behavior during Save Action

亡梦爱人 提交于 2019-12-24 09:59:30
问题 Scenario: We have a Dynamo DB table supporting Optimistic Locking with Version Number. Two concurrent threads are trying to save two different entries with the same primary key value to that Table. Question: Will ConditionalCheckFailedException be thrown for the latter save action? 回答1: Yes, the second thread which tries to insert the same data would throw ConditionalCheckFailedException . com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException As soon as the item is saved in

Optimistic concurrency in ADO.NET Entity Framework

纵然是瞬间 提交于 2019-12-22 04:51:10
问题 I found an MSDN article that describes how EF handles concurrency when saving changes: By default [...] Object Services saves object changes to the database without checking for concurrency . For properties that might experience a high degree of concurrency, we recommend that the entity property be defined in the conceptual layer with an attribute of ConcurrencyMode="fixed" I have two questions: Having no properties in my model where ConcurrencyMode="fixed" , is it safe for me to assume that

EF Concurrency Handling with Timestamp attribute in Model First approach

笑着哭i 提交于 2019-12-18 16:59:48
问题 I am trying to implement the solution given in Handling Concurrency with the Entity Framework in an ASP.NET MVC Application . The article says: Adding a Tracking Property to the Department Entity In Models\Department.cs, add a tracking property: [Timestamp] public Byte[] Timestamp { get; set; } The Timestamp attribute specifies that this column will be included in the Where clause of Update and Delete commands sent to the database. Since I'm using a model first approach, I followed steps 1 -

StaleObjectStateException vs OptimisticLockException

放肆的年华 提交于 2019-12-18 04:07:49
问题 A StaleObjectStateException is being thrown in my app instead of OptimisticLockException (as I read I should expect this one) when optimistic concurrency problem occurs in my app. No need to post code, as it's the most basic concurrency problem - wrong version in a timestamp column. How am I supposed to get OptimisticLockException, not the other one? 回答1: StaleObjectStateException is thrown when you use straight hibernate API. OptimisticLockException is thrown if you used JPA style hibernate.

Entity Framework Optimistic Concurrency Exception not occuring

青春壹個敷衍的年華 提交于 2019-12-17 16:37:30
问题 We have an ASP.Net MVC application that uses EF4 as its data access layer and we're seeing unexpected behaviour with regards to OptimisitcConcurrencyExceptions not being thrown when we think they should be. We have simplified the problem down to the following code... using System.Linq; using Project.Model; namespace OptimisticConcurrency { class Program { static void Main() { Contact firstContact = null; using (var firstEntities = new ProjectEntities()) { firstContact = (from c in

Entity framework OptimisticConcurrencyException rethrown after refresh

别等时光非礼了梦想. 提交于 2019-12-13 15:37:52
问题 I'm using a timestamp column to check the concurrency in my entity. The exception is correctly thrown when data is not the same in 2 different contexts. When such an exception occurs when saving, I call the following method to handle it: public static void HandleOptimisticConcurrencyException(ObjectContext context, OptimisticConcurrencyException ex) { string msg = @"The data has changed while you were editing it. If you save, your changes will override the previous ones. If you don't, your

How to use optional attributes in web service update messages (DTOs)?

余生颓废 提交于 2019-12-13 15:33:15
问题 BACKGROUND Assume you have a (SOAP) web service, BookService , managing books in a library. In the information model assume that the Book entity has the following attributes: id author publisher title shelfId In order to manipulate the data four web service operations are defined: AddBook GetBook UpdateBook DeleteBook Request and response message are defined for each operation. However, the design of the update message XML schemas is more complicated. We would like to achieve the following

RavenDB Catch 22 - Optimistic Concurrency AND Seeing Changes from Other Clients

自古美人都是妖i 提交于 2019-12-11 03:39:30
问题 With RavenDB, creating an IDocumentSession upon app start-up (and never closing it until the app is closed), allows me to use optimistic concurrency by doing this: public class GenericData : DataAccessLayerBase, IGenericData { public void Save<T>(T objectToSave) { Guid eTag = (Guid)Session.Advanced.GetEtagFor(objectToSave); Session.Store(objectToSave, eTag); Session.SaveChanges(); } } If another user has changed that object, then the save will correctly fail. But what I can't do, when using

RavenDB UseOptimisticConcurrency in Config?

自闭症网瘾萝莉.ら 提交于 2019-12-11 02:53:03
问题 Is there a way to set optimistic concurrency to true in Raven.Server.exe.config? Or, can it somehow be applied at the database level? On RavenDB's site, I see a couple of mentions of setting UseOptimisticConcurrency = true, but it looks like it's at the session level within the code: public void Save<T>(T objectToSave) { using (IDocumentSession session = Database.OpenSession()) { session.Advanced.UseOptimisticConcurrency = true; // This is the setting Guid eTag = (Guid)session.Advanced