Page 1 of 1

Optimistic Locking

Posted: Mon 21 Mar 2011 16:04
by FrankHealy
Gents could anyone point me to an implimentation of Optimistic locking using EF4 POCO objects?

Posted: Tue 22 Mar 2011 15:03
by AndreyR
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.