Custom field/custom relations!!

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 31-Mar-2009 16:14:40   

Hi, Using Ver 2.5, Adapter, SQL server 2005, VB, WinForm

My Activity table has a 1:m with FundPlan table, using ActivityID.

Activity table: (ActivityID, ActivityCode, ProjectCode) FundPlan table: (PlanID, ProjectCode, ActivityID, Amount)

I want to return a datatable filtered on FundPlan containing: (ProjectCode, ActivityCode, Amounta)

eg; ... table = New DataTable table.TableName = "FundPlanned" fields = New ResultsetFields(3) fields.DefineField(FundPlanFields.ProjectCode, 0, "ProjectCode") fields.DefineField(ActivityFields.ActivityCode, 1, "ActivityCode") fields.DefineField(FundPlanFields.Amounta, 2, "Amounta", AggregateFunction.Sum) ...

I can't use ProjectCode and table FundPlan does not include field ActivityCode.

Is it possible to include field ActivityCode in my datatable and relate it to ActivityCode in table Activity?

Thanks for any suggestions.

<EDIT>

Sorry, just thought - As a 1:m relationship already exists, will ActivityCode in the statement fields.DefineField(ActivityFields.ActivityCode, 1, "ActivityCode") be automatically populated with the relevant ActivityCode data from table Activity?

Thanks

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 31-Mar-2009 21:25:31   

It won't automatically be populated - you also need to add the relation object that will have been generated between the two entities

This example is from the documentation

DataAccessAdapter adapter = new DataAccessAdapter();
ResultsetFields fields = new ResultsetFields(3);
fields.DefineField(EmployeeFields.FirstName, 0, "FirstNameManager", "Manager");
fields.DefineField(EmployeeFields.LastName, 1, "LastNameManager", "Manager");
fields.DefineField(EmployeeFields.LastName, 2, "AmountEmployees", "Employee", AggregateFunction.Count);
IRelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.Relations.Add(EmployeeEntity.Relations.EmployeeEntityUsingEmployeeId, "Employee", "Manager", JoinHint.None);

IGroupByCollection groupByClause = new GroupByCollection();
groupByClause.Add(fields[0]);
groupByClause.Add(fields[1]);
DataTable dynamicList = new DataTable();
adapter.FetchTypedList(fields, dynamicList, bucket, 0, null, true, groupByClause);

it actually uses a generated relation to jointhe employee table to itself, but should be enough to get you going... simple_smile

Matt