I have multiple services using same table and i want to lock table using EF,if some service is already using it.
I try to do this with the help of below solution but it doesn't work
How can I lock a table on read, using Entity Framework?
For more Information
I try to use this code from "Service 1" at the same time I have use "Service 2" call same function but it still retrieve data from table.
** I want "Service 1" call function then table have be lock and "Service 2" can't retrieve data or do anything is it possible to this?
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead }))
{
var newUrl = dbEntity.URLs.FirstOrDefault(url => url.StatusID == (int) URLStatus.New);
if(newUrl != null)
{
newUrl.StatusID = (int) URLStatus.InProcess;
dbEntity.SaveChanges();
}
scope.Complete();
}