views:

77

answers:

1

Based on what I can see the answer is no, but there is always a possibility

A: 

Stored procedures are compiled when executed, and the execution plan is then stored in an execution plan cache that SQL Server maintains. Unless there is some important change to the underlying tables (e.g. updated statistics, new indexes, manual request for recompilation etc) it will use the stored execution plan.

Linq-to-SQL ad-hoc queries use the sp_executesql stored procedure. The result of this is that they too are stored in SQL Server's execution plan cache, so running the same query* multiple times will only lead to SQL Server compiling it once and thereafter using the cached plan. (* = same query as in same number and same type of parameters)

That said, Linq-to-SQL also does a certain amount of work when translating the linq expression trees into SQL queries. The overhead of this varies but for very complex queries that are executed frequently this can be noticable.

To lower the cost of repeatedly translating the same query to SQL, Linq-to-SQL has something called CompiledQuery. Unfortunately the CompiledQuery class only support up to four parameters per query so for complex queries [where it would have a greater impact than it does on very simple queries] it is usually ruled out as an option due to this limitation. It is also worth noting that CompiledQuery SQL queries do not take advantage of L2S client-side predicate elimination so if you use the CompiledQuery class it is worth comparing the SQL-server-side cost (esp. in terms of I/O) if you have any where clause predicates that could potentially be eliminated client side...

KristoferA - Huagati.com