How to read 'blocks' of records...

3 posts, 0 answers
  1. gmendez
    gmendez avatar
    82 posts
    Member since:
    Jun 2012

    Posted 21 May 2009 Link to this post

    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. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 22 May 2009 Link to this post

    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.
  3. DevCraft banner
  4. gmendez
    gmendez avatar
    82 posts
    Member since:
    Jun 2012

    Posted 22 May 2009 Link to this post

    Heloo PetarP,

    Very easy ;) !!
    Thanks a lot.

    Regards,

    Gonzalo
Back to Top