How to filter a object's related collection

Posts   
 
    
Gareth
User
Posts: 24
Joined: 09-Apr-2004
# Posted on: 03-Jun-2004 13:48:29   

When filtering as below the mapper returns 'all' of the tutors in the table that are not deleted, rather than just the school's tutors that are not deleted.

        
         SchoolEntity school = new SchoolEntity();
         school.FetchUsingPK( this.SchoolID );

IPredicateExpression filter = new PredicateExpression();
         filter.Add(PredicateFactory.CompareValue(NQTTutorFieldIndex.IsDeleted, ComparisonOperator.Equal, false));
         school.Tutors.GetMulti(filter, 0, null);


Are we doing this wrong simple_smile ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 03-Jun-2004 14:53:18   

Yes, you are just fetching a bunch of objects into the collection of School. simple_smile The collection 'Tutors' in school, is the facility to fetch the tutors related to the school object.

If you want to filter these further, you have to use the GetMulti() method of a new TutorCollection object, and specify the school's PK as well, or do as you do now and specify the school's PK as well. This last option seems odd, however the logic in place to fetch the Tutors is just fetching all tutors for a given school, namely the school containing the tutors collection to fetch

Frans Bouma | Lead developer LLBLGen Pro
Gareth
User
Posts: 24
Joined: 09-Apr-2004
# Posted on: 03-Jun-2004 22:16:53   

Yes, odd as this does seem the same seems to apply for sorting a retrieved collection.

So with the last option, basically what you are saying is that the mapper only filters that schools tutors but we must also add the schoolid to the filter list?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 03-Jun-2004 22:33:03   

The generated code passes the school object to the TutorCollection's GetMulti() method, which then constructs a filter with the school's PK values.

So you can create a new filter and store the objects in the School.Tutors collection (clear it first!) you can also fetch the tutors in a separate collection, as you are just fetching a subset of the entities available based on a set of criteria.

Frans Bouma | Lead developer LLBLGen Pro