问题
My project is C# and uses CastleProject ActiveRecord on MS SQL Server database.
I need to retrieve N consequent items from the database, sorted by some criteria, started from some value.
Example: I have a lot of messages in some table, where message has ID, time and text. I'd like to retrieve messages with position from 100 to 120, when they are sorted by time.
I cannot read all messages, and then sort and find on a client because there may be many messages in database (say it, a million of).
Is it possible to achieve with ActiveRecord means or only with stored procedures on SQL Server?
回答1:
Assuming your AR class is MyItem
and it inherits ActiveRecordBase<T>
:
MyItem[] items = MyItem.SlicedFindAll(100, 20, new[] {Order.Asc("time")});
来源:https://stackoverflow.com/questions/3707200/read-n-consequent-items-by-activerecord