This is a continuation from the following discussion:

Datamaps - Join to the same table twice - Part 1

Add Join Relationships

Now we need to add 2 join relationships in the am_LoadRelationshipMaps method.  Both of these joins will be similar but they will use different joinTableAlias.  Also, the fields that you are joining on should be different.

/// <summary>
/// Loads maps to join two database files.
/// </summary>
public override Dictionary<stringAB_RelationshipMap> am_LoadRelationshipMaps()
{
    var relationshipMap = new AB_RelationshipMapsDictionary(ap_PrimaryTable);


    relationshipMap.am_AddRelationshipMap(JoinTableName, useDistinctJoins: false, joinTableAlias: JoinTableAlias1)
        .am_JoinWhere(primaryTableField: "PrimaryFieldJoinKey1", joinTableField: "JoinKey");

    relationshipMap.am_AddRelationshipMap(JoinTableName, useDistinctJoins: false, joinTableAlias: JoinTableAlias2)
        .am_JoinWhere(primaryTableField: "PrimaryFieldJoinKey2", joinTableField: "JoinKey");
    return relationshipMap;
}

Add datamaps for Join Fields

Once the relationship maps are added we can now setup the datamaps for the join fields.  They are the same as normal join field datamaps with the exception that for the targetTable: instead of specifing the Join Table Name we need to use the Join Table Alias.

//Join Alias 1 fields
maps.am_AddDataMap("JoinField1", ExampleEntity.JoinTableAlias1JoinField1Property, targetTable: JoinTableAlias1);
maps.am_AddDataMap("JoinField2", ExampleEntity.JoinTableAlias1JoinField2Property, targetTable: JoinTableAlias1);

//Join Alias 2 fields
maps.am_AddDataMap("JoinField1", ExampleEntity.JoinTableAlias2JoinField1Property, targetTable: JoinTableAlias2);
maps.am_AddDataMap("JoinField2", ExampleEntity.JoinTableAlias2JoinField2Property, targetTable: JoinTableAlias2);

Notice that the two sets of join fields are the same field names from the database tables but use different properties on the Entity.