This is just odd and I am hoping someone can explain it to me. Today when doing a EF query (see below) I received the following error.

Here is the original EF Query which was causing the error

At first I was a bit stumped because this same query worked inside of LINQPad, which I know is using Linq-to-sql not Linq-to-Entities but they are close enough.
After a bit of thinking and staring at the code I thought maybe it was the compiler warning about access to disposed closures when accessing the ‘db’ variable, but that was not the issue either.
For grins I decided to remove the .ToList() from my statement (making it look like below) and it simply worked.

What I don’t understand really is WHY? Does anyone out there know the reason why?
Till next time,
Posted
05-18-2012 6:38 AM
by
Derik Whittaker