0
我从实体框架和存储库模式开始。我对ObjectContext感到困惑。 每次我们需要它时实例化它会更好吗? 我使用这样的:Global ObjectContext还是本地的?
private GenericRepository _genericRepository;
public EmployeeDAO()
{
var _context = new NorthwindEntities();
this._genericRepository = new GenericRepository(_context);
}
public Employee FindByID(int employeeID)
{
Employee _employee = this._genericRepository.Single<Employee>(x => x.EmployeeID == employeeID);
return _employee;
}
可能重复[?是用静态的LINQ to SQL的DataContext在asp.net可以保持交易(HTTP ://stackoverflow.com/questions/5324147/is-maintain-the-transaction-with-a-static-linq-to-sql-datacontext-in-asp-net-poss) – Steven
阅读此:http:// stackoverflow .COM /问题/ 3653009 /实体框架,和连接池/ 3653392#3653392 –