ObeyWeakRelations, isn't

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 05-Apr-2007 13:50:02   

I'm doing something silly, but can't figure it out.

I would like a list of all the Charities(parent) and their contributions(children) between a date, but I always want all the Charities regardless if they have a contributions. ObeyWeakRelations is the answer?

I am getting **only **those Charities with contributions in the date range. I need all Charities always.

//My charity collection
CharityOrganizationCollection charityCol = new CharityOrganizationCollection();

//Prefetch the contributions
PrefetchPath prefetch = new PrefetchPath((int)EntityType.CharityOrganizationEntity);
prefetch.Add(CharityOrganizationEntity.PrefetchPathContributions);

//Sort by Name
ISortExpression sort = new SortExpression(new SortClause(CharityOrganizationFields.Name, SortOperator.Ascending));

//Add relations so we can filter on the date
RelationCollection relationsToUse = new RelationCollection();
relationsToUse.Add(CharityOrganizationEntity.Relations.ContributionEntityUsingCharityOrganizationFk);
relationsToUse.ObeyWeakRelations = true; 

//Filter on the contribution date
IPredicateExpression select = new PredicateExpression();
select.Add(new FieldBetweenPredicate(ContributionFields.ContributionDate,FROM,TO));

//Get'm
charityCol.GetMulti(select, 0, sort,relationsToUse,prefetch);
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 05-Apr-2007 14:06:12   

I checked the DQE output and the date filter is applied to the first SQL which gets the Charities(parent) with a Left joins to Contributions(child).

Should it not do the date filter on the second SQL where the contributions are retrieved? If not how do I move the date filter predicate to the second SQL where the contributions are retrieved?

Thanks for helping me understand this.

LLBL info: (March 19th v2 C#, VS2005)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Apr-2007 16:42:46   

Just fetch the Charities and specify the filter (between a date range) to the prefetchPath of the Contributions.

Don't use relations, at all.