Friday, May 18, 2012

EntityCollection or EntityReferece error in EF when using .ToList()

EntityCollection or EntityReferece error in EF when using .ToList():
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.
image
Here is the original EF Query which was causing the error
image
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.
image
What I don’t understand really is WHY?  Does anyone out there know the reason why?
Till next time,


ICT4PE&D

No comments:

Post a Comment

Thank's!