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.