开发者

Allow for Database changes

开发者 https://www.devze.com 2023-01-26 15:13 出处:网络
can anyone tell me approaches to tackling the following which is a very typical use case. User 1 is editing page 1 which is modifying a users roles etc.

can anyone tell me approaches to tackling the following which is a very typical use case.

User 1 is editing page 1 which is modifying a users roles etc. User 2 is also modifying the开发者_Go百科 same user as user 1. How do i prevent the changes overwriting one another???

this is for asp.net site with framework 3.5???

thanks Niall


Optimistic concurrency is very common here, often using the ROWVERSION (aka TIMESTAMP in SQL server) data type. Most ORMs will handle this automatically (detecting the presence of a ROWVERSION/TIMESTAMP) - otherwise you will need to handle this in your code.

At the simplest level; you keep hold of the ROWVERSION you fetched when you fetched the record for editing, and check it when you attempt to save. If it matches, the save is committed; otherwise you throw an exception (the second edit loses).

Note you can (as an alternative) check each column during the update; this is more granular, but more costly (and it doesn't fully cope with some scenarios with inter-dependent properties).

0

精彩评论

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