I am using ASP.NET to build a application for a retail company. I am using the Entity Framework (model-first) as my data access layer. I am using stored procedures to do my CRUD operations and all columns are mapped and seems to be correct as all CRUD functionality are working as expected.
But I am having concurrency issues with the DELETE operation.
I've added a TimeStamp
column to the table I am doing the CRUD operation on. The UPDATE operation works fine as it is updating by primary key and the TimeStamp
value. Thus if no rows are affected with the UPDATE operation, because of a change in the TimeStamp
value, the Entity Framework throws a OptimisticConcurrencyException
.
The DELETE
operation works on the same principle as it is deleting by primary key and the TimeStamp
value. But no exception is thrown when the TimeStamp
value does not match between the entity and the database.
In the C# delete method I do retrieve the latest record first and then update the TimeStamp
property to another TimeStamp
value (It might be different to the retrieved value). After some investigation by using SQL Profiler I can see that the DELETE
stored procedure is executed but the TimeStamp
parameter that is passed to the stored procedure is the latest TimeStamp
value and not the value that I have set the TimeStamp
property to. Thus the record is deleted and the Entity Framework does not throw an exception.
Why would the Entity Framework still pass the retrieved TimeStamp
value to the Stored Procedure and not the value that I have assigned the property? Is this be design or am I missing something?
Any help will be appreciated! (where is Julie Lerman when you need her! :-))