views:

19

answers:

2

I wonder how the DataContext handles concurrency violation.

For example -

Two users are fetching some data from the database, then some of them change some row and commit changes, then other user trying commit their changes so a ChangeConflictException should occur, but how does the DataContext know that the data has changed?

Fetching this data again and comparing? Or some database notification mechanism?

A: 

Concurrency control can be done by using either TimeStamp column in database or UpdateCheck attribute in LINQ-to-SQL.

MSDN Concurrency Overview (LINQ-to-SQL)

MSDN How to manage change conflicts (LINQ-to-SQL)

Kthurein
A: 

The previous values of all columns that aren't being changed and are marked UpdateCheck are included in the where clause of the generated update statement. If the update affected 1 row, all is well- if it affected 0 rows (eg, somebody else changed one of those values, hence it couldn't locate the row after filtering), you get the ChangeConflictException.

nitzmahone