Relationcollection in a query

Posts   
 
    
HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 28-May-2005 17:32:36   

Excuse my flooding of posts but i'm on a tight shedule here stuck_out_tongue_winking_eye

In my code i have searchscreens where the user can enter filter fields In this particular example i have a searchscreen for a perceelcollection, where a user can filter on Postcode (which is a field of a location object linked to a perceel)


                PerceelCollection pc = new PerceelCollection();
                RelationCollection rc = new RelationCollection();
                rc.Add(PerceelEntity.Relations.LocationCodeEntityUsingLocationId);
                PredicateExpression pe = new PredicateExpression();
                filter = txtPostcode_nt.Text;
                if (filter!="")
                                                pe.Add(PredicateFactory.Like(LocationCodeFieldIndex.PostcodeCode,"%"+filter+"%"));

                PrefetchPath pp =new PrefetchPath((int)EntityType.PerceelEntity);
                pp.Add(PerceelEntity.PrefetchPathLocationCode);
                SortExpression sorter = new SortExpression(SortClauseFactory.Create(PerceelFieldIndex.PlId,SortOperator.Ascending));
                pc.GetMulti(pe,0,sorter,rc,pp);

Now, the location subobject of a perceel is nullable, and all percelen with such a null LOCATION_ID are never retrieved in the query. I would assume that they should be retrieved if the user doesn't specify a postcode filter ?

However, if i move the relation collection adding into the IF-clause, then all percelen are fetched if no postcode-filter is provided. Is this normal behavior that when you use a RelationCollection, all records with a NULL FK are filtered out of the resultset ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 28-May-2005 17:43:41   

INNER join is the default. If you want also NULL valued related FK's, you should specify a JoinHint when you add the relation to the relationcollection (use one of the overloads). If you don't want to use aliassing (and you don't need it here) specify string.Empty for the alias.

Frans Bouma | Lead developer LLBLGen Pro