EntityCollection Iteration

Posts   
 
    
NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 16-Apr-2005 00:35:04   

This has more to do with my lack of knowledge for how to properly find items in an IList than it does anything else, but I am using an Entity collection so I get to ask it here.

I am using the adapter scenario (which won't really matter, but there you are anyway). I have a StudentEntity and I have retrieved his StudentEntity.Registrations (classes) for today's date. I then have another EntityCollection that contains the all the attendance records for this student and all his classes for this same day. Therefore, the column I am matching to in both lists is the ClsID (class ID) field.

So, my pseudo code looks like:

Retrieve Collection of this.Students.Registrations
Retreive Collection of AttendanceEntities where stu_id = '123' and cal_date = today

For each registration in RegistrationCollection
      Find the corresponding AttendanceEntity in AttnCollection where cls_id = registration.cls_id

...what I'm not sure how to do is the part inside my for loop. How do I find the record inside the AttnCollection that matches my record in the RegistrationCollection?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 16-Apr-2005 11:27:42   

I'm probably misunderstanding the question, but why not do:

foreach AttendanceEntity attendance in registration.Attendances { if(attendance.ClsId == registration.ClsId) { // add to collection with objects we're looking for } }

Frans Bouma | Lead developer LLBLGen Pro
NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 18-Apr-2005 18:28:02   

Otis wrote:

I'm probably misunderstanding the question, but why not do:

foreach AttendanceEntity attendance in registration.Attendances { if(attendance.ClsId == registration.ClsId) { // add to collection with objects we're looking for } }

I didn't explain myself very well. Let's start with the basis:

If I have an EntityCollection, how do I find the entity within that collection that has clsID == 12345? Is my only option to itterate through the list?

NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 18-Apr-2005 18:47:28   

NickD wrote:

Otis wrote:

I'm probably misunderstanding the question, but why not do:

foreach AttendanceEntity attendance in registration.Attendances { if(attendance.ClsId == registration.ClsId) { // add to collection with objects we're looking for } }

I didn't explain myself very well. Let's start with the basis:

If I have an EntityCollection, how do I find the entity within that collection that has clsID == 12345? Is my only option to itterate through the list?

Never mind. You can ignore this. I found the section in the Help that has to do with what I'm after. Thanks for writing that whenever you did simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Apr-2005 20:48:33   

No problem simple_smile

Frans Bouma | Lead developer LLBLGen Pro