I have to have optimistic concurrency within my data model which inlcudes inheritance. At the moment I get too many concurrency exceptions, especially when I update a property multiple times within the same context.
Here are the steps to reproduce my problem:
Just create a very simple base entity "MyBaseObject" with three properties:
- DBKey (int, primary key, StoreGeneratedPattern = Identity)
- Name (string, allows null)
- RowsetVersion (int64, allows null, StoreGeneratedPattern = Computed, default value = 0, Concurrency Mode = Fixed)
And create an enity "MyObject" deriving from "MyBaseObject" with just one property:
- Content (string, allows null)
I chose "Table per Type" and "File per Entity" in my code generation options and generated the database from my model.
I added this trigger to the generated ddl:
CREATE OR REPLACE TRIGGER UPD_MyObjects
BEFORE UPDATE ON "MyObjects"
FOR EACH ROW
BEGIN
UPDATE "MyObjectBases" SET "RowsetVersion" = "RowsetVersion" + 1 WHERE "DBKey" = :NEW."DBKey";
END UPD_MyObjects;
I know it only handels updates on my "MyObjects"-table. But that's OK for now.
Now I run the following code:
Code: Select all
using (DataEntities entities = new DataEntities()) {
try {
MyObject testOrder = new MyObject();
testOrder.Name = "Hans";
testOrder.Content = "MyContent";
entities.MyObjectBases.AddObject(testOrder);
entities.SaveChanges();
testOrder.Content = "MyNewContent";
entities.SaveChanges();
testOrder.Content = "MyNewExtraContent";
entities.SaveChanges();
}
catch (Exception e) {
}
}
(Btw. I have the same issue within MsSql and the .Net provider. The only way to get MsSql and Entity Framework to not throw the exception is by changing the type of RowsetVersion to timestamp in the database and to binary in my entity model)
Now my questions are:
- Is there a best practise of handling optimistic concurrency in models with inheritance?
- I guess there is no type like the built in MsSql-timestamp in Oracle for handling this concurrency issue, right?
- Any suggestions on how to deal with this?
I am really looking forward to your answers
Andi