ADO. Optimistic concurrency in net Entity Framework

I found that an MSDN article describes how EF handles concurrency when saving changes:

I have two questions:

>There is no property of ConcurrencyMode = "fixed" in my model. I can safely assume that an optimisticconcurrencyexception is thrown when saving the changes. This is because the entity no longer exists in the data store, that is, it has been deleted by another user, or did I make a mistake?

I think EF will execute an update statement that looks like this. As I can see, if the person with id = 1 does not exist, it will only raise an optisticconcurrencyexception:

UPDATE Person SET FirstName = 'John' AND LastName = 'Smith' WHERE ID = 1

>When using ConcurrencyMode = "fixed", will EF also check concurrency when deleting entities? In other words, does EF execute delete statements that look like this (not just the primary key in the where clause):

DELETE FROM Person WHERE ID = 1 AND LastName = 'Doe'

Solution

Good question

(1) Yes, but unfortunately, it's not that simple Because ef (3.5) has an independent association model, the association is also handled independently. Even if you don't say so, it will become part of the concurrency check during updates and deletes

That is, when you update person, you often see the following updates:

UPDATE Person SET Partner = NULL AND FirstName = 'John' AND LastName = 'Smith' 
WHERE ID = 1 AND Partner = 2

Partner is FK column

If you use FK correlation, all this will change in 4.0, as we expect

(2) For delete, check any ConcurrencyMode = 'fixed' attribute during deletion The exception is when you have a SPROC for delete that does not accept the concurrency value

I hope this can help

Alex

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>