开发者

Entity Framework Concurrency with Multiple Tables/Entities

I understand how to make optimistic concurrency work with Entity Framework for a single table.

But what about the scenario where I want to have optimistic concurrency across multiple tables. To illustrate what I mean, I will use an example:

  • Car table
  • Wheel table, foreign key to Car (multiple wheels per car)

How can I manage concurrency in the case where the ser adds/removes a Wheel from the Car.

Adding a ModifiedTimestamp column in the Car can handle concurrent updates to Car, but what about udpates to the Car's Wheel?

I can only imagine solving this by using pessimistic concurrency (ie - locking the car object to a user) to solve this. But from my research, it seems that pessmistic concurrency is not supported by Entity Framework.

This is just a very simple example, and I'm wondering how ever开发者_运维问答yone solves this type of scenario in general. I can imagine there are many situations where you have an entity, which has related entites, and should all be considered as one in terms of concurrent updates.


One way is always modify something in the Car table. Car is aggragetion root for your wheels because wheels cannot exists without Car. If you modify wheel you modify whole aggragated object - car. So add some car update to model this behavior - common is maintaining some column like ModifiedDate.

Pesimistic concurrency is supported by serialized transaction - default isolation level for TransactionScope.


Pessimistic concurrency is supported, just place all your data access inside a Transaction Scope.

One simple strategy that you can use is last person to udate the record wins, all other changes are lost. This is not always acceptable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜