开发者

How To Handle Concurrency Using An ORM

开发者 https://www.devze.com 2023-01-13 06:47 出处:网络
Suppose I was writing an application where user开发者_StackOverflow中文版s had to book appointments (in my case, a user is paired with an employee and that employee will do work for that user at a par

Suppose I was writing an application where user开发者_StackOverflow中文版s had to book appointments (in my case, a user is paired with an employee and that employee will do work for that user at a particular time of day). How would I ensure that 2 users did not end up booking the same appointment using NHibernate or Entity Framework? Would I open a transaction and do something like:

BeginTransaction();

if(!AppointmentBooked(userId, employeeId, time)) // read
   BookAppointment(userId, employeeId, time); // write

CommitTransaction();


Check this article out it might be helpful. I had a problem like yours. Entity Framework has the ability of doing non-optimistic concurrency via configuration.

http://msdn.microsoft.com/en-us/library/bb738618.aspx

0

精彩评论

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