-1
我有多个服务使用相同的表,我想锁定表使用EF,如果某些服务已经在使用它。EF可以锁表吗?
我尝试用以下解决方案的帮助下做到这一点,但它不工作
How can I lock a table on read, using Entity Framework?
欲了解更多信息
我尝试使用从“服务1”这个代码在同时我使用“服务2” 调用相同的功能,但它仍然从表中检索数据。
**我想要“服务1”调用函数,然后表有锁,“服务2”无法检索数据或做任何事情都可以这样吗?
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();
}
问题寻求帮助调试(“为什么不是这个代码的工作?”)必须包括所期望的行为,一个特定的问题或错误的和必要的最短的代码在问题本身中重现它。没有明确问题陈述的问题对其他读者无益。请参阅:如何创建最小,完整和可验证示例。 – TheGameiswar
谢谢。我会添加更多信息。 – Witchayanin