views:

712

answers:

4

As far as I know, in MS SQL Server 2000+ stored procedures are compiled, and run faster than normal non-compiled queries. I wonder if MS SQL Server also compiles LINQ to SQL queries, and caches that compilation, for performance purposes.

+1  A: 

SQL Server doesn't know about LINQ.

As far as I know, LINQ runs just as a library that uses the queries to generate SQL queries that are then sent to the server as SQL text commands.

Alan Jackson
+1  A: 

As far as I know, it behaves as normal queries to SQL Server. You can always call Stored Procedures with LINQ to SQL if benefits exist for your specific case.

Gustavo
+3  A: 

When it comes to the execution plan in SQL Server there is no major differences in speed with stored procedures vs normal non-compiled queries. See this for more information about other factors about speed.

LINQ-to-SQL generates normal paramatised queries (SQL Server knows nothing about LINQ, the app generates normal SQL) so the balance is the same. That is if you aren't using the LINQ-to-SQL functions which call Stored Procs (assuming you meant the query stuff).

You may also want to read this, which is a similar question, but focuses on the more important benefits of LINQ vs StoredProcs

Robert MacLean
+1  A: 

MS SQL Server caches the query plans for anything TSQL that is run against it. Once the plan is cached, the query will run a bit faster. I know that there is an expiration time for this cache, but I haven't asked the dba's about it.

As far as I know, MS SQL Server 2000 was the last one that compiled the stored procs. That's not done anymore. That's why a lot of inline queries are just as fast (with SQL Server 2000+).

hectorsosajr