predicate and aggregates

Posts   
 
    
erichar11
User
Posts: 268
Joined: 08-Dec-2003
# Posted on: 21-Mar-2005 10:22:35   

In my app, I allow a user to setup a set of Milestonetemplates and each milestonetemplate has a set of milestone Activities and foreach MilestoneActivity their is corresponding data which is filtered by what page the user is on. So I have the following table relations:

MilestoneTemplate 1:N MilestoneActivities 1:N MilestoneActivitiesData

In code I do the following:

 public static DataTable GetMilestoneActivities2(MilestoneTemplateEntity template, PageEntity page)
        {
            DataTable dt = new DataTable();
            RelationPredicateBucket bucket = new RelationPredicateBucket();
            IPredicateExpression expression = new PredicateExpression();
            DataAccessAdapter adapter = new DataAccessAdapter(true);
            ResultsetFields fields = new ResultsetFields(4);
            fields.DefineField(MilestoneActivityFieldIndex.ActivityName,0,"ActivityName");
            fields.DefineField(MilestoneActivityDataFieldIndex.PlannedDate,1,"PlannedDate");
            fields.DefineField(MilestoneActivityDataFieldIndex.ActivityStatus,2,"Status");
            fields.DefineField(MilestoneActivityDataFieldIndex.ActualDate,3,"ActualDate");
            
            bucket.Relations.Add(PageEntity.Relations.MilestoneTemplateEntityUsingMilestoneTemplateId);
            bucket.Relations.Add(MilestoneTemplateEntity.Relations.MilestoneActivityEntityUsingMilestoneTemplateId);
            bucket.Relations.Add(MilestoneActivityEntity.Relations.MilestoneActivityDataEntityUsingMilestoneActivityId);        
            
            expression.Add(PredicateFactory.CompareValue(MilestoneTemplateFieldIndex.MilestoneTemplateId, ComparisonOperator.Equal,template.MilestoneTemplateId));
            expression.AddWithAnd(PredicateFactory.CompareValue(MilestoneActivityDataFieldIndex.PageId, ComparisonOperator.Equal,page.PageId));
            bucket.PredicateExpression.Add(expression);
            adapter.FetchTypedList(fields, dt,bucket);
            adapter.CloseConnection();
            return dt;
        }

However, this results in multiple repeating rows foreach milestoneActivity and I'm not sure why? I assume it's because the 1:N relation between MilestoneActivity and MilestoneActivityData, but that's why I created the filter on PageId to limit the results.

ex. (this happens for each milestone activity)

Define 3/19/2005 11:13:00 PM Not Started 3/19/2005 11:13:00 PM Define 3/19/2005 11:13:00 PM Not Started 3/19/2005 11:13:00 PM Define 3/19/2005 11:13:00 PM Not Started 3/19/2005 11:13:00 PM Define 3/19/2005 11:13:00 PM Not Started 3/19/2005 11:13:00 PM Define 3/19/2005 11:13:00 PM Not Started 3/19/2005 11:13:00 PM Define 3/19/2005 11:13:00 PM Not Started 3/19/2005 11:13:00 PM Define 3/19/2005 11:13:00 PM Not Started 3/19/2005 11:13:00 PM

Is this where aggregates are supposed to be applied? If so how does know which field to apply the aggregate to? Suggestions here would be great. Maybe I'm going about this all wrong.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 21-Mar-2005 14:25:57   

Use the FetchTypedList overload which accepts a boolean for allowDuplicates and specify false for that parameter. Default is true.

Frans Bouma | Lead developer LLBLGen Pro