I have some short code that looks like this:
public static IQueryable<User> SelectFromEmployee(int employee)
{
using (var ctx = Database.AccountingContext())
{
return ctx.Users.Where(c => c.Employee_FK == employee);
}
}
If i just keep this code as it is and use the result i get en exception telling me that the data is disposed. But if I do like this:
public static IEnumerable<User> SelectFromEmployee(int employee)
{
using (var ctx = Database.AccountingContext())
{
return ctx.Users.Where(c => c.Employee_FK == employee).ToList();
}
}
Everything works just fine. But my problem is that i want to use Linq Dynamic that require IQueryable. Is there any way to return a local IQueryable so i can continue working with it?
If you want to literally do what you’re asking
beware though that what you return is no longer associated with a data context, so relationship navigation for example, will not work as you might expect if the data context had not been disposed.