I have an application that implements entity framework 4.1, i use a context instance for every method
object select()
{
using(DBContext context = new DBContext())
{
return context.table.Where(e => e.id == 1).FirstOrDefault();
}
}
void update(entity)
{
using(DBContext context = new DBContext())
{
context.Attach(entity);
context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
context.SaveChanges();
}
}
it work fine, the problem is that the application es multi-user and they can modify the same records, i want to prevent that one user change a record that is being modifying by other user until update the record
entity = select(); // get the record and lock it
// do some change ,nobody can modify this record in the db
update(); // update the record and unlock it
is there some way to achieve this?