I am learning EF 5 and am trying to understand the reason for passing a repository from the main window (load point) into a View Model.
I have read that the best way to use context
is via the using block
like so:
// within CompanyViewModel
using (var _context = new MyEntities())
{
var _query = from co in _context.Companies
select co;
this.AllCompanies = new ObservableCollection<Models.Company>(_query);
}
where MyEntities
is the object created by VS in the EDMX file.
So my question is if I can simply call MyEntities from a ViewModel, why would I pass a repository (a reference to MyEntities
) into each ViewModel?