If I write a large SQL statement with many group by clauses and so on; would it be much faster with normal SQL (maybe a stored procedure), or is Linq only parsing it to a very nice SQL statement and gives me my results quite fast?
+7
A:
In some cases you may be able to tune the SQL better than LINQ to SQL... but LINQ really is running SQL. It's not fetching all the data into the process and then doing the processing. You can (and should) log what SQL is being generated and profile anything that looks suspicious.
Of course, there's the overhead of converting the query into SQL to start with (which is why you're able to precompile them) and then there's the overhead of converting the data into objects - and keeping track of the IDs etc. In my experience this is usually not a significant overhead though. As ever, profile your code...
Jon Skeet
2009-09-18 06:43:15
If something about the DB preformance looks werid, run the sql-profiler and look at execution times of the queries.if any queries are very slow, you sould look into methods for chaning that query.
AndreasN
2009-09-18 07:06:46
If you just want to understand what sql is being produced in the background, Linqpad (http://www.linqpad.net/) has a very nice feature where, when you run a linq query, it not only shows you the results, but also the sql commands that were run.
sgmoore
2009-09-18 08:44:11