11using System ;
22using System . Collections . Generic ;
3+ using System . Linq ;
34using System . Text . RegularExpressions ;
45using NHibernate . Collection ;
56using NHibernate . Engine ;
@@ -18,7 +19,7 @@ public class JoinWalker
1819 private readonly HashSet < AssociationKey > visitedAssociationKeys = new HashSet < AssociationKey > ( ) ;
1920 private readonly IDictionary < string , IFilter > enabledFilters ;
2021 private readonly IDictionary < string , IFilter > enabledFiltersForManyToOne ;
21- private static readonly Regex aliasRegex = new Regex ( @"( [\w]+)\. " , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
22+ private static readonly Regex aliasRegex = new Regex ( @"[\w]+(?=\.) " , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
2223
2324 private string [ ] suffixes ;
2425 private string [ ] collectionSuffixes ;
@@ -206,12 +207,12 @@ protected virtual SelectMode GetSelectMode(string path)
206207 private static int [ ] GetTopologicalSortOrder ( List < DependentAlias > fields )
207208 {
208209 TopologicalSorter g = new TopologicalSorter ( fields . Count ) ;
209- Dictionary < string , int > _indexes = new Dictionary < string , int > ( ) ;
210+ Dictionary < string , int > indexes = new Dictionary < string , int > ( StringComparer . OrdinalIgnoreCase ) ;
210211
211212 // add vertices
212213 for ( int i = 0 ; i < fields . Count ; i ++ )
213214 {
214- _indexes [ fields [ i ] . Alias . ToLower ( ) ] = g . AddVertex ( i ) ;
215+ indexes [ fields [ i ] . Alias ] = g . AddVertex ( i ) ;
215216 }
216217
217218 // add edges
@@ -222,9 +223,9 @@ private static int[] GetTopologicalSortOrder(List<DependentAlias> fields)
222223 {
223224 for ( int j = 0 ; j < dependentAlias . DependsOn . Length ; j ++ )
224225 {
225- var dependentField = dependentAlias . DependsOn [ j ] . ToLower ( ) ;
226+ var dependentField = dependentAlias . DependsOn [ j ] ;
226227 int end ;
227- if ( _indexes . TryGetValue ( dependentField , out end ) )
228+ if ( indexes . TryGetValue ( dependentField , out end ) )
228229 {
229230 g . AddEdge ( i , end ) ;
230231 }
@@ -240,26 +241,26 @@ private static int[] GetTopologicalSortOrder(List<DependentAlias> fields)
240241 /// </summary>
241242 private void AddAssociation ( string subalias , OuterJoinableAssociation association )
242243 {
243- subalias = subalias . ToLower ( ) ;
244+ var dependentAlias = new DependentAlias
245+ {
246+ Alias = subalias ,
247+ } ;
248+ _dependentAliases . Add ( dependentAlias ) ;
244249
245- var dependencies = new List < string > ( ) ;
246250 var on = association . On . ToString ( ) ;
247- if ( ! String . IsNullOrEmpty ( on ) )
251+ if ( ! string . IsNullOrEmpty ( on ) )
248252 {
253+ var dependencies = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
249254 foreach ( Match match in aliasRegex . Matches ( on ) )
250255 {
251- string alias = match . Groups [ 1 ] . Value ;
252- if ( alias == subalias ) continue ;
253- dependencies . Add ( alias . ToLower ( ) ) ;
256+ string alias = match . Value ;
257+ if ( string . Equals ( alias , subalias , StringComparison . OrdinalIgnoreCase ) )
258+ continue ;
259+ dependencies . Add ( alias ) ;
254260 }
261+ dependentAlias . DependsOn = dependencies . ToArray ( ) ;
255262 }
256263
257- _dependentAliases . Add ( new DependentAlias
258- {
259- Alias = subalias ,
260- DependsOn = dependencies . ToArray ( )
261- } ) ;
262-
263264 associations . Add ( association ) ;
264265 }
265266
0 commit comments