In order to use joins you will be using an auxiliary class called AJoin which will be added to the ADataSet definition using the alJoins property. The joins are built using ATables and AForeignKey objects.
AJoin class
The AJoin class will be constructed using the ATable and AForeignKey. Also you will be able to specify join option such as "INNER JOIN", "RIGHT/LEFT OUTER JOIN", or "FULL JOIN".
For example if you want to create a dataset to bring customers and their orders you can use the ACustomer and AOrder.fkCust.
Customer vCustomer = new Customer();
Order vOrder = new Order();
ADataSet vdsJoinTest = new ADataSet(vCustomer);
vdsJoinTest.alJoins.Add(new AJoin(vOrder, vOrder.fkCust));
vdsJoinTest.alAddCols(vCustomer);
vdsJoinTest.alAddCols(vOrder);
vdsJoinTest.alFill();
foreach (DataRow vRow in vdsJoinTest.alGetCurrentRows())
{
vdsJoinTest.alGetValues(vRow, vCustomer, vOrder);
Console.WriteLine(vCustomer.GetFormattedValues());
Console.WriteLine(vOrder.GetFormattedValues());
}
The AJoin requires the table and the foreign key to link to one of the tables in the dataset.
The sql for the example bellow is:
SELECT [CUSTOMER].[ID], [CUSTOMER].[NAME], [CUSTOMER].[MAXCREDIT] , [CUSTOMER].[ISACTIVE], [CUSTOMER].[CUSTSINCE],
[ORDER].[NUMBER], [ORDER].[CUSTID], [ORDER].[ORDDATE], [ORDER].[ADDRESS], [ORDER].[CITY], [ORDER].[STATE], [ORDER].[ZIP]
FROM [CUSTOMER]
INNER JOIN [ORDER] ON [ORDER].[CUSTID] = [CUSTOMER].[ID]
AJoin option
The join supports the following options:
You can specify the option by passing a third parameter to the AJoin class. And you can use the predefined parameters in the AJoin class. The INNER JOIN is the default, which is the most common case.
Bellow is the example to use the LEFT OUTER JOIN that will bring all customers even if they don't have associated orders.
vdsJoinTest.alJoins.Add(new AJoin(vOrder, vOrder.fkCust, AJoin.Option.LEFT_OUTER_JOIN));
That's it for joins, next we will take a look at how ADataSet handle DataRows.