Basic looping through Collection

Posts   
 
    
aure303
User
Posts: 6
Joined: 06-Jun-2007
# Posted on: 06-Jun-2007 14:31:40   

Hello,

Sorry for asking such a simple question but basically I have a "ContactEntity" which contains: - a string field called Name - a string field called Email - a boolean field called ReceiveEmail

What I'd like to do is create a list or array or some collection of some sort with all the contacts which have ReceiveEmail set to true so that i can loop through them to get the email field for each and use that to email these people. Also I need to do all that in the code behind. Is it possible to do something similar to that: ContactCollection contacts = new ContactCollection("ReceiveEmail", "1"); I know this particular code wont work but you get the idea. Thanks a lot in advance. BTW i'm using llblgenpro 2

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Jun-2007 15:28:37   

Do you want to fetch only those entities from the database? Solution: You should add a filter (ContactFields.ReceiveEmail == true) to the fetch method, PLease refer to the LLBLGen Pro manual: "Using the generated code -> Adapter/SelfServicing -> Filtering and Sorting"

Or you already have fetched all the entities and you want to do client side filtering? Solution: Use an EntityView, as described in the manual "Using the generated code -> SelfServicing/Adapter -> Using the EntityView class"

aure303
User
Posts: 6
Joined: 06-Jun-2007
# Posted on: 07-Jun-2007 14:32:41   

Thank you for pointing me to the filtering... and the manual... i must admit i should have looked there first flushed

Anyway i sorted my problem. The solution was (if anyone's interested):

ContactCollection contacts = new ContactCollection(); IPredicate filterElement = (ContactFields.IsBookingManager == 1); contacts.GetMulti(filterElement);

foreach (ContactEntity contact in contacts) { objEmail.To.Add(contact.Email); }

Thank you again for your help and quick answer!