I'm new to C# and LINQ, but the latter is pretty cool. Except I can't figure out what is going on here:
I have the following piece of code, which runs as expected; it sorts and selects the top 100 records:
IEnumerable<workerLog> query =
(from record in _gzClasses.workerLogs
orderby record.workerID, record.timeStamp ascending
select record).Take(100);
foreach(var record in query)
{
Console.WriteLine(record.timeInSession.ToString());
}
but when I do the following, the same lines print, but then the program hangs a bit and a SQLException is thrown saying the server timed out.
IEnumerable<workerLog> query =
from record in _gzClasses.workerLogs
orderby record.workerID, record.timeStamp ascending
select record;
foreach(var record in query.Take(100))
{
Console.WriteLine(record.timeInSession.ToString());
}
What in the world is the difference here? Does it have something to do with the way LINQ queries are executed? Coming from the Java world, it makes no sense.