In order to join to the same table twice we need to alais the tables. This is supported in the Accelerator Datamaps and is an option to Alias the tables by default when generating a module.
Define constants for tables
private const string PrimaryTableName = "[dbo].[PrimaryTable]"; private const string PrimaryTableAlias = "primaryTableAlias"; private const string JoinTableName = "[dbo].[JoinTable]"; private const string JoinTableAlias1 = "joinTableAlias1"; private const string JoinTableAlias2 = "joinTableAlias2";
Setup alias for Primary Table
Now in the am_LoadFieldMaps method we setup the primary table to use the alias name. If your code is using the AB_DataMapsDictionary for creating the datamaps all you need to do is set the ap_PrimaryTable to the alias name and the ap_AliasedTable to the actual primary table name.
/// <summary> /// Defines the maps for the Data Source Field Names and Entity Properties for module. /// </summary> public override Dictionary<string, AB_DataSourcePropertyReference> am_LoadFieldMaps(string qualifier) { // Set the Primary File Name, Foreign fields will have to be mapped on a case-by-case basis ap_PrimaryTable = PrimaryTableAlias; ap_AliasedTable = PrimaryTableName; //Create a dictionary to hold the maps var maps = new AB_DataMapsDictionary(ap_PrimaryTable, qualifier);
Continued in the following discussion:
Datamaps - Join to the same table twice - Part 2