@@ -147,14 +147,14 @@ string GenerateTableAlias(Type tableType)
147147 return tableAlias ;
148148 }
149149
150- string GenerateColumnAlias ( PropertyInfo pi )
150+ string GenerateColumnAlias ( PropertyInfo pi , Type tableType )
151151 {
152152 if ( pi == null )
153153 throw new ArgumentNullException ( nameof ( pi ) ) ;
154154
155155 var columnName = conventions . GetColumnName ( pi ) ;
156156 var columnAlias = columnName ;
157- var tableName = conventions . GetTableName ( pi . DeclaringType ) ;
157+ var tableName = conventions . GetTableName ( tableType ) ;
158158
159159 if ( columnAliasMappingCount . TryGetValue ( columnName , out int columnAliasCount ) )
160160 {
@@ -211,13 +211,13 @@ string GetTableAliasFromName(string tableName)
211211 string GetTableAliasFromType ( Type tableType )
212212 => GetTableAliasFromName ( GetTableNameFromType ( tableType ) ) ;
213213
214- string GetColumnAliasFromProperty ( PropertyInfo pi )
214+ string GetColumnAliasFromProperty ( PropertyInfo pi , Type tableType )
215215 {
216216 if ( pi == null )
217217 throw new ArgumentNullException ( nameof ( pi ) ) ;
218218
219219 var columnName = conventions . GetColumnName ( pi ) ;
220- var tableName = conventions . GetTableName ( pi . DeclaringType ) ;
220+ var tableName = conventions . GetTableName ( tableType ) ;
221221 var columnMapping = tableColumnAliasMapping [ tableName ] ;
222222
223223 if ( ! columnMapping . ContainsKey ( columnName ) )
@@ -258,7 +258,7 @@ string GetColumnAliasFromProperty(PropertyInfo pi)
258258
259259 foreach ( var pi in properties . Values )
260260 {
261- GenerateColumnAlias ( pi ) ;
261+ GenerateColumnAlias ( pi , mainTableType ) ;
262262 }
263263
264264 // -----------------------------------------------------------------------------------------------------------
@@ -270,7 +270,7 @@ string GetColumnAliasFromProperty(PropertyInfo pi)
270270 // Default select
271271 select = string . Join ( $ ",{ Environment . NewLine } \t ", properties . Select ( x =>
272272 {
273- var colAlias = GetColumnAliasFromProperty ( x . Value ) ;
273+ var colAlias = GetColumnAliasFromProperty ( x . Value , mainTableType ) ;
274274 var colName = x . Key ;
275275
276276 return $ "[{ mainTableAlias } ].[{ colName } ] AS [{ colAlias } ]";
@@ -307,7 +307,7 @@ string GetColumnAliasFromProperty(PropertyInfo pi)
307307 . Where ( DotNetToolkit . Repository . Extensions . Internal . PropertyInfoExtensions . IsPrimitive )
308308 . Select ( x =>
309309 {
310- var colAlias = GenerateColumnAlias ( x ) ;
310+ var colAlias = GenerateColumnAlias ( x , joinTableType ) ;
311311 var colName = conventions . GetColumnName ( x ) ;
312312
313313 return $ "[{ joinTableAlias } ].[{ colName } ] AS [{ colAlias } ]";
@@ -449,7 +449,7 @@ string GetColumnAliasFromProperty(PropertyInfo pi)
449449 var tableName = GetTableNameFromType ( tableType ) ;
450450 var tableAlias = GetTableAliasFromName ( tableName ) ;
451451 var sortingPropertyInfo = ExpressionHelper . GetPropertyInfo ( lambda ) ;
452- var columnAlias = GetColumnAliasFromProperty ( sortingPropertyInfo ) ;
452+ var columnAlias = GetColumnAliasFromProperty ( sortingPropertyInfo , tableType ) ;
453453
454454 sb . Append ( $ "[{ tableAlias } ].[{ columnAlias } ] { ( sortOrder == SortOrder . Descending ? "DESC" : "ASC" ) } , ") ;
455455 }
0 commit comments