Core Concepts > Basic Queries
Offset and Limit (Pagination)
Use the Offset
and Limit
methods while composing a query to return a window of results. dbExpression deviates from Microsoft SQL Server on syntax - but using familiar C# Linq syntax just felt right on this one.
dbExpression deviates from Microsoft SQL Server syntax of OFFSET and FETCH NEXT ROWS ONLY when building queries.
//skip the first 10 matched records, and only return 10 records
IEnumerable<Person> people = db.SelectMany<Person>()
.From(dbo.Person)
.OrderBy(dbo.Person.DateCreated.Desc())
.Offset(10)
.Limit(10)
.Execute();
//skip the first record, and return all remaining records
IEnumerable<Person> notTheLastPersonToRegister = db.SelectMany<Person>()
.From(dbo.Person)
.OrderBy(dbo.Person.RegistrationDate.Desc())
.Offset(1)
.Execute();