我从实体框架和存储库模式开始。我对 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;
}