开发者

How To Handle Concurrency Using An ORM

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜