Is there a way to limit TOP rows returned by OrmLite select using Linq Expression?
Asked Answered
C

1

6

It seems like OrmLite Select(predicate) function it brings back everything in the where clause (across the network) and then applies the .Take(x) on top of that.

I need a way to only bring back the TOP x so the results are faster and use less bandwidth.

Is there a way to limit TOP rows returned by OrmLite select (using a Linq Expression)?

Catabolism answered 11/2, 2014 at 4:39 Comment(0)
A
10

Limit and Offset support is available using the Limit() expression, e.g::

Take 10 Rows

var rows = db.Select<Table>(q => q.Where(x => x.Name != null).Limit(10));

Skip 5 Rows, Take 10

var rows = db.Select<Table>(q => q.Where(x => x.Name != null).Limit(5,10));
Altruist answered 11/2, 2014 at 9:7 Comment(1)
This be done with the Expression<Func<T,bool>> overload too... var lambda = OrmExtensions.BuildLambdaDynamic<VHVIN>(search.Where); vehicles = db.Select<VHVIN>(q => q.Where(lambda).Limit(search.Take));Catabolism

© 2022 - 2024 — McMap. All rights reserved.