Tuesday, September 17, 2013

LINQ Does Not Compile

Today I learned that LINQ to SQL statements are not compiled as normal .NET code is.  Instead, it's somehow transformed into a normal SQL statement by finding a comparator that operates on the conditions you gave and checking to see if it has the right argument types.  So, don't just go and write any boolean-producing expression as the Where part of a query; it's better to collect all the parts of it in a line before and use simple variables instead.  Remember, the SQL server isn't passing every data row back to your query for inspection; LINQ just writes all the fancy query stuff for you.

No comments:

Post a Comment