LINQ Conflict Detection: Setting UpdateCheck Attribute

I read in LINQ recently to start implementing it, and there is a special thing about how it generates UPDATE queries that bother me.

Creating entity code automatically using SQLMetal or Object Relational Designer, it is obvious that all fields for all tables will receive the UpdateCheck.Always attribute , which means that for each UPDATE and DELETE query, I get the SQL as follows:

UPDATE table SET a = 'a' WHERE a='x' AND b='x' ... AND z='x', ad infinitum

Now call me a purist, but it seems Extremely ineffective for me, and it is just like a bad idea, even if it was not ineffective. I know that the selection will be performed by a clustered primary key so as not to slow down, but SQL still needs to check every field after that to make sure it matches.

Of course, in some very sensitive applications this may be useful, but for a typical web application (I think the stack overflows) it seems that UpdateCheck.WhenChanged will be more suitable by default, and I personally would prefer UpdateCheck.Never , since LINQ will update only the changed fields, and not all the fields, and in most real cases the second person editing something wins in any case.

This means that if two people manage to edit the same field of the same line in a short time between reading this line and turning on UPDATE, then the conflict that will be found will not be triggered. But actually this is a very rare case. The only thing we can pay attention to when two people change the same thing, will not be caught by this, because they will not click "Send" at the same time in any case, therefore there will be no conflict during the second DataContext reads and updates the record (unless the DataContext remains open and remains in the session when the page is displayed or some other bad idea).

However, as it rarely happens, I would really like to not get exceptions in my code from time to time if this happens.

, : , ? ( , "" -, ) - , UpdateCheck.Always ?

: ? SQLMetal ORD, UpdateCheck?
, , , , , , - SQLMetal , , , , , dev.

?
, .

!

+3
1

, - . "" concurrency, timestamp , .

- , SqlMetal (UpdateCheck = Always), , , UpdateCheck = Never . SqlMetal ).

, , , SqlMetal null "Delete On Null" ( , ). -, .

+2

Source: https://habr.com/ru/post/1705410/


All Articles