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

Restricting the records fetched based on a condition

1 Answer 84 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ashok Sridhar
Top achievements
Rank 1
Ashok Sridhar asked on 20 Jan 2009, 06:58 PM
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.

Thanks

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 22 Jan 2009, 01:39 PM
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.

Regards,
Alexander
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Getting Started
Asked by
Ashok Sridhar
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or