This is a migrated thread and some comments may be shown as answers.

How to read 'blocks' of records...

2 Answers 47 Views
OQL (OQL specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
gmendez
Top achievements
Rank 1
gmendez asked on 21 May 2009, 05:32 PM
Hello,

I'd like to know if it's possible to retrieve blocks of records of a predefined size.
For example, read records 0 to 9, then 10 to 19, 20 to 29 and so on.
I'd like to do this because of performance optimizations using WCF Services. I've seen some simple examples in LINQ but I'd like to know if it's possible to achieve the same functionality with OQL.

Thanks in advance,

Gonzalo

2 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 22 May 2009, 07:09 AM
Hi gmendez,
yes this is possible using OQL. You just need to take advantage of the MaxResultCount and Skip properties of the IQuery class. Here is an example:
 static void Main(string[] args) 
        { 
            IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope(); 
            IQueryResult result = CustomSelection(10, 10, scope); 
            foreach (Order ord in result) 
            { 
                Console.WriteLine(ord.OrderID); 
            } 
            Console.ReadKey(); 
             
        } 
        private static IQueryResult CustomSelection(int numberToTake, int fromWhereToStart, IObjectScope scope) 
        { 
            IQuery oqlQuery = scope.GetOqlQuery("Select * from OrderExtent"); 
            oqlQuery.MaxResultCount = numberToTake; 
            oqlQuery.Skip= fromWhereToStart ; 
            IQueryResult result = oqlQuery.Execute(); 
            return result; 
        } 

Note that the skip property specifies how many records to skip  from all the data. If you set it to 10 than the query will return all records starting from the eleventh. The MaxResultCount specifies how many records the result should take.

Kind regards,
PetarP
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
gmendez
Top achievements
Rank 1
answered on 22 May 2009, 10:57 AM
Heloo PetarP,

Very easy ;) !!
Thanks a lot.

Regards,

Gonzalo
Tags
OQL (OQL specific questions)
Asked by
gmendez
Top achievements
Rank 1
Answers by
PetarP
Telerik team
gmendez
Top achievements
Rank 1
Share this question
or