title: Why does sp_executesql run slower when parameters are passed as arguments
body: <p>Query 1: (lightning fast)</p>
  
  <pre><code>sp_executesql "select * from tablesView where Id = 1"
  </code></pre>
  
  <p>vs.</p>
  
  <p>Query 2: (too slow)</p>
  
  <pre><code>sp_executesql "select * from tablesView where Id = @Id", N"@Id int", @Id=1
  </code></pre>
  
  <p><code>tablesView - a view containing multiple joins</code></p>
  
  <p>LINQ always converts queries to Query2 form and hence the performance is really bad.</p>
  
  <p>Questions: I need reason for query2 slowness, and any resolution if there's one. 
  And a resolution for LINQ. </p>
  
  <p>----Additional comments:</p>
  
  <p>The performance hit is definitely because of the 2 columns which are using ranking functions(row_number) but I can't avoid them I need them.</p>