foreach(var name in _cust.Select(s => s.Username).Distinct())
{
var x = _cust.Select(s => s.Username == name); //ERROR HERE
//rest of the code here
}
will throw There is already an open DataReader associated with this Command which must be closed first.
Exception, however it doesn't happen when I add .ToList()
.
I've search around so far but haven't found a satisfied answer. So my question is :
- Is there any other way to do this beside adding
.ToList()
? - If I use
.ToList()
as a solution, will this cause a performance problem when it goes to production? Because AFAIKToList()
will try to load everything in the memory. - I have a lot of navigation properties in my Entities, will
ToList()
tried to load everything inside navigation properties?
Thanks