Two query filters are LINQ or #
Consider this table in the examples:
ID | NOME
---------------------------------------------
1 | Cliente 1
2 | Cliente 2
3 | Cliente 3
4 | Cliente 4
5 | Cliente 5
6 | Cliente 6
7 | Cliente 7
8 | Cliente 8
9 | Cliente 9
10 | Cliente 10
11 | Cliente 11
12 | Cliente 12
Take
Returns a specified number of adjacent elements from the beginning of a sequence.
Usage:
// retorna os 3 primeiros elemento da tabela
var r = Session.QueryOver<Cliente>().Take(3).List();
Output:
ID | NOME
---------------------------------------------
1 | Cliente 1
2 | Cliente 2
3 | Cliente 3
SQL equivalent query (Firebird 2.1):
SELECT first 3 CL.ID, CL.NOME FROM CLIENTE CL
Skip : >
Ignores a specified number of elements in a sequence and returns the remaining elements.
Usage:
// retorna todos os items apartir do 2° elemento da tabela
var r = Session.QueryOver<Cliente>().Skip(2).List();
Output:
ID | NOME
---------------------------------------------
3 | Cliente 3
4 | Cliente 4
5 | Cliente 5
6 | Cliente 6
7 | Cliente 7
8 | Cliente 8
9 | Cliente 9
10 | Cliente 10
11 | Cliente 11
12 | Cliente 12
SQL equivalent query (Firebird 2.1):
SELECT skip 2 CL.ID, CL.NOME FROM CLIENTE CL
Use Together:
// retorna os 3(take) primeiros elementos apartir do 2°(skip) elemento da tabela
var r = Session.QueryOver<Cliente>().Take(3).Skip(2).List();
Output:
ID | NOME
---------------------------------------------
3 | Cliente 3
4 | Cliente 4
5 | Cliente 5
SQL equivalent query (Firebird 2.1):
SELECT first 3 skip 2 CL.ID, CL.NOME FROM CLIENTE CL
These techniques are used constantly, for pagination of queries, bringing better performance to the application. Where only the desired lines are obtained from the database.