【发布时间】:2013-02-06 20:44:20
【问题描述】:
我使用的是 EF 5.0 Code First。我们无法对每个读取查询实施 nolock。请在下面找到代码。
我的模特:
public class UserType
{
public UserType()
{
CreationDate = DateTime.Now;
UpdatedDate = DateTime.Now;
DeletedFlag = false;
}
public int UserTypeId { get; set; }
public string UserTypeName { get; set; }
public int CreatedBy { get; set; }
public int UpdatedBy { get; set; }
public DateTime CreationDate { get; set; }
public DateTime UpdatedDate { get; set; }
public bool DeletedFlag { get; set; }
}
RepositoryBase:(我们使用的是存储库设计模式)
public IQueryable<T> Query<T>() where T : class
{
return DataContext.Set<T>();
}
服务:
//TODO: place NOLOCK
repBase.Query<UserType>().Where(ja => ja.DeletedFlag == false).OrderByDescending(ja => ja.UpdatedDate).ToList();
repBase 是要在 Query() 之上调用的 DB 上下文的实例。
现在我们要使用 (NOLOCK) 运行上述查询。
Visual Studio 2012, EF 5.0 代码优先, C#.Net 4.0, MVC Web API, 存储库设计模式
提前致谢。
【问题讨论】:
-
您无法使用 EF 发出无锁提示(或任何提示)。但是,只是好奇,你需要它做什么?
-
为了避免死锁和允许脏读,内部应用会修改数据,但面向公众的网站只是只读的
标签: c#-4.0 visual-studio-2012 ef-code-first entity-framework-5