title: How To execute SQL Query in ASP.NET Core API
body: <p>I have this SQL Query :</p>
  <pre><code>DECLARE @pageNo int=1
  DECLARE @pageSize int=2
  
  SELECT top 2 id,
  Title,
  Author,
  NumberOfPages,
  PublishedAt,
  RowNumber
  FROM 
  
  (
  
  SELECT top 2 id, Title, Author,
  NumberOfPages,PublishedAt,
  Row_Number() over (order by id desc) as RowNumber 
  FROM Books 
  
  )T
  WHERE
  T.RowNumber BETWEEN ((@pageNo-1)*@pageSize)+1 AND (@pageNo*@pageSize)
  </code></pre>
  <p>I want Execute this SQL Query with C# in ASP.NET core</p>
  <p>I tried this Code :</p>
  <pre><code>[HttpGet]
  public async Task&lt;ActionResult&lt;IEnumerable&lt;Books&gt;&gt;&gt; GetBooks()
          {
            
  
    
        return await _context.Books.FromSqlRaw(&quot;Select * from Books where id = 2&quot;).ToListAsync();
  
             
  
          }
  </code></pre>
  <p>But this Code work only with Single Sql Query Line like last example</p>
  <pre><code>Select * from Books where id = 2
  </code></pre>
  <p>but when I try with Complex SQL Query with Multi lines is not Working</p>
  <p>I hope your help</p>
  <p>thank so much</p>