Optimistic Locking

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
FrankHealy
Posts: 5
Joined: Mon 14 Mar 2011 15:58

Optimistic Locking

Post by FrankHealy » Mon 21 Mar 2011 16:04

Gents could anyone point me to an implimentation of Optimistic locking using EF4 POCO objects?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 22 Mar 2011 15:03

The solution is to create a 'before update' trigger, and set the concurrency property in it like this:

Code: Select all

CREATE OR REPLACE TRIGGER MyTableConcur
  BEFORE UPDATE ON MyTable FOR EACH ROW
BEGIN 
   :NEW."Version" := :OLD."RowsetVersion" + 1; 
   -- alternative: :NEW."Version" := current_timestamp; 
END MyTableConcur;
Then set the StoreGeneratedPattern property to Computed for the version property in the Storage part of the Entity model, and set ConcurrencyMode to Fixed for this property in the Conceptual part of the model.

Post Reply