Restricting the records fetched based on a condition

Thread is closed for posting
2 posts, 0 answers
  1. Ashok Sridhar
    Ashok Sridhar avatar
    9 posts
    Member since:
    Dec 2006

    Posted 20 Jan 2009 Link to this post

    Hello all,

                I'm new to OpenAccess and trying to use this tool in one of my projects. I'm generated my domain using the reverse mapping and all is great.  I need to if there is a way to restrict the records fetched based on a condition.  For example, I have Customer and Orders classes (domain) and the Customer class contains an IList of Orders indicating the Orders belonging to that Customer.  I'm trying to see when I fetch the customers, only the orders that were placed in the last 6 months are fetched with it.  The reason being as the database grows (in terms of orders for each customer), I do not want to fetch all the orders and then filter them out in the business layer rather restrict my fetch itself.

                 Any pointers/help to accomplish this.

  2. Alexander
    Alexander avatar
    727 posts

    Posted 22 Jan 2009 Link to this post

    Hello Ashok Sridhar,

    We do not support such restriction but I am not sure whether you really need it. This is the benefit of lazy loading - the object is not fetched until it is used for the first time. So if you do not use these objects, they will not be loaded.
    Note that if you want to filter a collection (Customer.Orders from last 6 months for example) you can avoid the loading of whole objects by using an appropriate fetch plan. With fetch plans you can specify which fields of the objects you want to use and only these fields will be fetched. In your case you can load only OrderID and OrderDate values for each object in the Customer's Orders list. Then you can use only the latest orders if you want to:

    foreach (Customer c in resultCustomers) 
        foreach (Order o in c.Orders) 
            if (o.RequiredDate > DateTime.Parse("01-01-1998"))  
                // do some work with the order 

    This code will not cause the loading of objects that do not meet the requirements of the condition. However if you want  to reach a property that in not already fetched, it will be lazy loaded.
    You can find additional information about dealing with fetch plans in this article. Hope this helps.

    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top