I\'m writing some code to access a database using EntityFrameWork. The code is:
public IEnumerable GetRows(int id)
{
using (var context = new
If you don't call .ToList()
the enumerable will be evaluated after your using
clause finishes, and thus the data context will be disposed before evaluating the query.
IMO, you should consider making your repository handle this (by calling .ToList()
) as otherwise this issue is representative of an implementation detail leaking out.