Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paging in servicestack ormlite

I am looking for a good way to implement paging in ormlite and I found another question, which has this snippet:

var data = db.Select<address>(predicate).Skip((int) pageNumber).Take((int) pageSize).ToList();

Problem with the above is that it gets back all the results and then does the skip and take on it which defeats the purpose of paging.

At another google groups post I have found the same problem and a sample in a github issue is mentioned as a solution but the URL no longer works. Does anyone know how to correctly page using servicestack?

like image 641
Ali Avatar asked Sep 16 '13 09:09

Ali


People also ask

How do I use the new sequence support in ormlite?

To be able to use the new sequence support you'll need to use an SQL Server dialect greater than SQL Server 2012+, e.g: var dbFactory = new OrmLiteConnectionFactory ( connString, SqlServer2012Dialect. Provider ); Using the same JOIN Filter feature OrmLite also lets you add SQL Server Hints on JOIN Table expressions, e.g: var q = db.

Why use ormlite exec filters?

OrmLite's core Exec filters makes it possible to inject your own behavior, tracing, profiling, etc. It's useful in situations like wanting to use SqlServer in production but use an in-memory Sqlite database in tests and being able to emulate any missing SQL Server Stored Procedures in code:

Does ormlite support memory optimization in SQL Server?

Whilst only SQL Server and MySQL Support Exclusive Or: db. Select < Table > ( x => ( x. Flags ^ 2) == 3 ); OrmLite allows access to many advanced SQL Server features including Memory-Optimized Tables where you can tell SQL Server to maintain specific tables in Memory using the [SqlServerMemoryOptimized] attribute, e.g:

What is ormlite?

OrmLite provides terse and intuitive typed API's for database querying from simple lambda expressions to more complex LINQ-Like Typed SQL Expressions which you can use to construct more complex queries. To give you a flavour here are some examples: int agesAgo = DateTime. Today. AddYears ( -20 ).


1 Answers

Found the answer in ormlite's tests. Essentially we could use SqlExpressionVisitor's Limit() like this:

var result = db.Select<K>( q => q.Where(predicate).Limit(skip:5, rows:10 ) );

like image 76
Ali Avatar answered Oct 12 '22 22:10

Ali