Converting a SQL from Sql Server to LINQ from C #

3

I have an sql that looks something like this:

SELECT coluna1, coluna2, coluna3
  FROM
  (
      SELECT coluna1, coluna2, coluna3, ROW_NUMBER() OVER(ORDER BY coluna1, coluna3 desc) as row
       FROM tabela1
      WHERE coluna4 in ('a', 'b', 'c', 'd')
  ) A
 WHERE
        A.ROW BETWEEN 1 AND 5
ORDER BY  A.ROW

And I want to pass this statement to C # LINQ expression.

Note: I am using ROW_NUMBER OVER(...) to be able to identify the line number and be able to do something similar to what you have in ORACLE: SELECT ... FROM ... limit 1,5

    
asked by anonymous 18.12.2014 / 14:41

1 answer

2

Your ROW_NUMBER() would be something equivalent to Top from what I understood. For this your query could use Take that returns a specified number of contiguous elements from the beginning of a sequence.

Along with Skip that ignores a specified number of elements in a sequence and returns the remaining elements.

So I try to paginate your data.

var dados = (from t in tabela1
             where criterios....
            select new { Colunas....}).Skip(4).Take(5)
    
18.12.2014 / 15:08