API/CodeSamples/ShowJoinAliasTextboxes.md
... ...
@@ -79,6 +79,66 @@ Using Join Alias Textbox, user can distinguish the joined tables more clearly
79 79
![JoinAlias](/API/CodeSamples/ShowJoinAliasTextboxes/JoinAlias2.png)
80 80
81 81
82
+## How to implement 'join alias' via hardcoding
83
+
84
+Below is a sample code that shows how to hardcode aliasing specific table names
85
+
86
+```csharp
87
+public override void PreSaveReportSet(string name, ReportSet reportSet) {
88
+ //the collection of table names and the associated alias
89
+ Dictionary<string, string> tableNameToAlias = new Dictionary<string, string>();
90
+
91
+ //loop through the report's set of tables
92
+ foreach (JoinedTable jt in reportSet.JoinedTables) {
93
+ if (!String.IsNullOrEmpty(jt.Alias))
94
+ return;
95
+ if (!tableNameToAlias.ContainsKey(jt.TableName))
96
+ tableNameToAlias.Add(jt.TableName, LookupTableAlias(jt.TableName)); //Add the table and set the alias as the full name with special characters replaced
97
+ }
98
+ //Set all the tables in the report to have the table on the right side of the join reflect the alias of itself.
99
+ foreach (JoinedTable jt in reportSet.JoinedTables) {
100
+ jt.Alias = tableNameToAlias[jt.TableName];
101
+ if (!String.IsNullOrEmpty(jt.RightConditionTable))
102
+ jt.RightAlias = tableNameToAlias[jt.RightConditionTable];
103
+ }
104
+ //update the selected fields and filters on the report to reflect the new aliases of the joined tables
105
+ foreach (Report report in reportSet.Reports.AllValues) {
106
+ foreach (Field field in report.Fields)
107
+ if (field.DbColumn != null && field.DbColumn.Table != null)
108
+ field.AliasTable = tableNameToAlias[field.DbColumn.Table.FullName];
109
+ foreach (Filter filter in report.Filters)
110
+ if (filter.dbColumn != null && filter.dbColumn.Table != null)
111
+ filter.AliasTable = tableNameToAlias[filter.dbColumn.Table.FullName];
112
+ }
113
+ //update the selected filters on the entire reportSet to reflect the new aliases of the joined tables (in case of a dashboard)
114
+ foreach (Filter filter in reportSet.Filters)
115
+ if (filter.dbColumn != null && filter.dbColumn.Table != null)
116
+ filter.AliasTable = tableNameToAlias[filter.dbColumn.Table.FullName];
117
+ }
118
+
119
+
120
+// In this case, 'Orders' table is to be aliased as 'o1','Customers' as 'c1','Order Details' as 'od1' and so on
121
+ public string LookupTableAlias(string tableName) {
122
+ switch (tableName) {
123
+ case "[dbo].[Orders]":
124
+ return "o1";
125
+ case "[dbo].[Customers]":
126
+ return "c1";
127
+ case "[dbo].[Order Details]":
128
+ return "od1";
129
+ case "[dbo].[Employees]":
130
+ return "e1";
131
+ case "[dbo].[Suppliers]":
132
+ return "s1";
133
+ default:
134
+ return tableName.Replace("[", "").Replace("]", "").Replace(".", "_");
135
+ }
136
+
137
+
138
+```
139
+
140
+
141
+
82 142
83 143
84 144