We use queries generated by Linq for data retrieval but for INSERT and UPDATE we do not allow generated SQL, but restrict to the use of stored procedures.
I connected the Update and the Insert behaviour in the DBML to the stored procedures.
The procedures are called, the data gets inserted/updated = all if fine, except in the case of optimistic concurrency.
If a record was changed between retrieval and update, the update should fail.
When Linq generates the Update statement itself, it throws a ChangeConflictException as expected, but using the stored procedure no Exception is thrown.
Thanks a lot for any help on this!
When configuring the UPDATE behavior to use the update stored procedure, Linq2SQL generates a method that is not throwing concurrency exceptions.
To handle optimistic concurrency I found a proposed solution in the MSDN forums
You can implement the Update method yourself in the patial DataContext class and throw a ChangeConflictException.
To achieve this you have to:
WHERE columnA = OriginalValueA ...to update only if the values were not changedRETURN @@ROWCOUNTWorking, but not straight forward.
Any other options?