I'm calling same database from different applications using Entity Framework. However, when one application is reading/updating a record, I do not want other applications to read that data.
I tried with the following sample code; however, they are still able to read the record.
Any suggestion OR different approaches will be highly appreciated!
using (Entities context = new Entities(ConnectionString))
{
DBTable entity;
do
{
entity = context.DBTable
.Where(item => item.IsLock == false)
.FirstOrDefault();
if (entity != null)
{
// Map entity to class
......
// Lock the record; it will be unlocked later by a calling method.
entity.IsLock = true;
context.SaveChanges();
count++;
}
} while (entity != null && count < 100);
}
Edited: Basically, I read a record and do something (it sometimes take long). Then update the record with success/fail flag (if fail other can do that again). I do not want other applications do the successful task multiple times.