martijnb wrote:
xor wrote:
Your assumption about sp_executesql is incorrect. It uses indexes in the same way as, for example, query executed in the Query Analyzer.
From my experience, this is not true. In the past I've had some troubles where the same query executed via sp_executesql() resulted into a complete different execution plan. There was a 'WHERE field = @value OR field IS NULL' construction in the query that made the query optimizer go mad with sp_executesql().
Well, there are cases and there are cases. I would not stake on SQL Server to always behave like it's stated in the documentation. :) But, as i noticed ADO.NET internally use sp_executesql to execute queries, created with SqlConnection.CreateCommand. So it is at least expected to work well.
In case of NHibernate, there is no direct usage of sp_executesql in the code. It's ADO.NET's work. If you would write the same command and execute it manually (using ADO.NET) you most likely will get the same call with sp_executesql in it.