@@ -2148,13 +2148,18 @@ public string GenerateTableAlias(string rootAlias, int tableNumber)
2148
2148
if ( tableNumber == 0 )
2149
2149
return rootAlias ;
2150
2150
2151
- StringBuilder buf = new StringBuilder ( ) . Append ( rootAlias ) ;
2152
- if ( ! rootAlias . EndsWith ( "_" ) )
2153
- {
2154
- buf . Append ( '_' ) ;
2155
- }
2151
+ string x = rootAlias . EndsWith ( '_' )
2152
+ ? string . Empty
2153
+ : "_" ;
2154
+ return string . Concat ( rootAlias , x , tableNumber . ToString ( ) , "_" ) ;
2155
+ }
2156
2156
2157
- return buf . Append ( tableNumber ) . Append ( '_' ) . ToString ( ) ;
2157
+ public string GetSubclassAliasedColumn ( string rootAlias , int tableNumber , string columnName )
2158
+ {
2159
+ if ( string . IsNullOrEmpty ( rootAlias ) )
2160
+ return columnName ;
2161
+
2162
+ return GenerateTableAlias ( rootAlias , tableNumber ) + "." + columnName ;
2158
2163
}
2159
2164
2160
2165
public string [ ] ToColumns ( string name , int i )
@@ -3655,16 +3660,21 @@ protected void LogStaticSQL()
3655
3660
3656
3661
public virtual string FilterFragment ( string alias , IDictionary < string , IFilter > enabledFilters )
3657
3662
{
3658
- StringBuilder sessionFilterFragment = new StringBuilder ( ) ;
3663
+ var filterFragment = FilterFragment ( alias ) ;
3664
+ if ( ! filterHelper . IsAffectedBy ( enabledFilters ) )
3665
+ return filterFragment ;
3659
3666
3667
+ var sessionFilterFragment = new StringBuilder ( ) ;
3660
3668
filterHelper . Render ( sessionFilterFragment , GenerateFilterConditionAlias ( alias ) , GetColumnsToTableAliasMap ( alias ) , enabledFilters ) ;
3661
-
3662
- return sessionFilterFragment . Append ( FilterFragment ( alias ) ) . ToString ( ) ;
3669
+ return sessionFilterFragment . Append ( filterFragment ) . ToString ( ) ;
3663
3670
}
3664
3671
3665
3672
private IDictionary < string , string > GetColumnsToTableAliasMap ( string rootAlias )
3666
3673
{
3667
- IDictionary < PropertyKey , string > propDictionary = new Dictionary < PropertyKey , string > ( ) ;
3674
+ if ( SubclassTableSpan < 2 )
3675
+ return CollectionHelper . EmptyDictionary < string , string > ( ) ;
3676
+
3677
+ var propDictionary = new Dictionary < PropertyKey , string > ( ) ;
3668
3678
for ( int i = 0 ; i < SubclassPropertyNameClosure . Length ; i ++ )
3669
3679
{
3670
3680
string property = SubclassPropertyNameClosure [ i ] ;
@@ -3677,20 +3687,11 @@ private IDictionary<string, string> GetColumnsToTableAliasMap(string rootAlias)
3677
3687
}
3678
3688
}
3679
3689
3680
- IDictionary < string , string > dict = new Dictionary < string , string > ( ) ;
3690
+ var dict = new Dictionary < string , string > ( ) ;
3681
3691
for ( int i = 0 ; i < SubclassColumnTableNumberClosure . Length ; i ++ )
3682
3692
{
3683
- string fullColumn ;
3684
3693
string col = SubclassColumnClosure [ i ] ;
3685
- if ( ! string . IsNullOrEmpty ( rootAlias ) )
3686
- {
3687
- string alias = GenerateTableAlias ( rootAlias , SubclassColumnTableNumberClosure [ i ] ) ;
3688
- fullColumn = string . Format ( "{0}.{1}" , alias , col ) ;
3689
- }
3690
- else
3691
- {
3692
- fullColumn = col ;
3693
- }
3694
+ var fullColumn = GetSubclassAliasedColumn ( rootAlias , SubclassColumnTableNumberClosure [ i ] , col ) ;
3694
3695
3695
3696
PropertyKey key = new PropertyKey ( col , SubclassColumnTableNumberClosure [ i ] ) ;
3696
3697
if ( propDictionary . ContainsKey ( key ) )
@@ -3709,8 +3710,7 @@ private IDictionary<string, string> GetColumnsToTableAliasMap(string rootAlias)
3709
3710
{
3710
3711
foreach ( var key in GetSubclassTableKeyColumns ( i ) )
3711
3712
{
3712
- var alias = i == 0 ? rootAlias : GenerateTableAlias ( rootAlias , i ) ;
3713
- dict [ key ] = $ "{ alias } .{ key } ";
3713
+ dict [ key ] = GetSubclassAliasedColumn ( rootAlias , i , key ) ;
3714
3714
}
3715
3715
}
3716
3716
@@ -3753,7 +3753,7 @@ public virtual string OneToManyFilterFragment(string alias)
3753
3753
public virtual SqlString FromJoinFragment ( string alias , bool innerJoin , bool includeSubclasses )
3754
3754
{
3755
3755
return SubclassTableSpan == 1
3756
- ? new SqlString ( string . Empty ) // just a performance opt!
3756
+ ? SqlString . Empty // just a performance opt!
3757
3757
: CreateJoin ( alias , innerJoin , includeSubclasses ) . ToFromFragmentString ;
3758
3758
}
3759
3759
0 commit comments