How to search collections after using a prefetch

Posts   
 
    
ritzcoder
User
Posts: 7
Joined: 07-Sep-2004
# Posted on: 27-Dec-2004 21:35:45   

Hi. I have been trying to search a collection and I am having trouble figuring out the best way to do it. I have the following situation. Using a prefetch path in the Adapter class setup, I have created a fairly large EntityCollection of Customers. This EntityCollection is disconnected from the server at this point and I allow the client interface to alter the collection. This works great but I am having trouble undersanding how to search and fileter this collection. As an example, I would like to search this collection for all customers that have a birthdate between 2/1/1960 and 4/1/1975. I cannot figure out how to run this kind of search without going back to the server. I will not be able to go back to the server because the clients might be disconnected. ADO.NET has the ability to let me basically run a sort of sql looking query against a local data collection. Is there something similar in llblgen? I have read up on predicates and I see that they allow you to create filters to run against a SQL Server by calling adapter.Fetch... but I do not understand how to use them to search a local collection created from a prefetch. My understanding is that FetchEntityCollection will always attempt to contact the remote server for data. So, my question is: Given a EntityCollection object that has been populated with data using a prefetch, what is the best way to run searches on this collection without having to reconnect to the server.

Thanks very much for any help.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 28-Dec-2004 13:50:52   

There is no local 'filter' method build into the entity collection. So you have to traverse the collection yourself (this is done by ado.net in a dataview as well, so there is no difference there). A filter on date as you describe can be accomplished with a simple forloop which tests a particular date field if it's > the min date and < the max date of the interval and if it is, the entity is added to a new entitycollection.

Frans Bouma | Lead developer LLBLGen Pro
ritzcoder
User
Posts: 7
Joined: 07-Sep-2004
# Posted on: 28-Dec-2004 15:01:29   

Hi. Thanks for the quick response. Your suggestion will work fine for me - I just wanted to make sure that there was not another way of doing this before I dived into it. Thanks again for llblgen - it is a great product!