问题
in ServiceStack OrmLite v3 you could do:
var rows = db.Select<Employee>().Limit(10));
Or:
var rows = db.Select<Employee>().Limit(5, 10)); // skips 5 then takes 10
However I cannot find these methods any longer in v4.
I suppose I can do the following instead:
var rows = db.SelectLazy<Employee>().Take(10);
However how can I do a db.Select
(not having to write direct SQL) which will translate to (in SQLite for example):
SELECT * FROM Employee LIMIT 10;
Also, is it possible to write an equivalent query for the below (again without having to write direct SQL)?
SELECT * FROM Employee ORDER BY Age;
Thanks.
回答1:
In ServiceStack.OrmLite v4, Limit() seems to only be available as an extension of SqlExpression<T>
. To build a query:
var query = db.From<SWChars>().Limit(10);
query = query.Where<SWChars>(char =>
char.FirstName == "Jar Jar" &&
char.FunnyLines < 0);
var result = db.Select<SWChars>(query);
I hope this helps someone out. It took me a few hours of Googling.
回答2:
I can see the OrderBy
/ OrderByDescending
in the documentation, it looks like:
var rows = db.SelectLazy<Employee>().OrderBy<Employee>(e=>e.Age).Take(10);
This might help with the Limit
issue ServiceStack.OrmLite: Where is the method to write custom SQL and get result set back?
来源:https://stackoverflow.com/questions/25057574/why-does-the-limit-method-no-longer-exist-in-the-servicestack-ormlite-v4