I\'m new to EF and I\'m trying to use an extension method which converts from my Database type User
to my info class UserInfo
.
I\'m using data
This can be as simple as adding ToList() in your repository. For example:
public IEnumerable GetMyObjectsForId(string id)
{
using (var ctxt = new RcContext())
{
// causes an error
return ctxt.MyObjects.Where(x => x.MyObjects.Id == id);
}
}
Will yield the Db Context disposed error in the calling class but this can be resolved by explicitly exercising the enumeration by adding ToList() on the LINQ operation:
public IEnumerable GetMyObjectsForId(string id)
{
using (var ctxt = new RcContext())
{
return ctxt.MyObjects.Where(x => x.MyObjects.Id == id).ToList();
}
}