@@ -24,9 +24,11 @@ public static IEnumerable<T> GetValues<T>()
2424 return cache . GetValues < T > ( ) ;
2525 }
2626
27- public static IEnumerable < T > LoadRelatedData < T > ( IEnumerable < T > values , IncludeSpecification includeSpecification )
27+ private static IList LoadData ( IList values , IEnumerable < INavigation > navs )
2828 {
29- foreach ( INavigation nav in includeSpecification . NavigationPath )
29+ INavigation nav = navs . FirstOrDefault ( ) ;
30+
31+ if ( nav != null )
3032 {
3133 IEntityType t ;
3234 IClrPropertyGetter [ ] objProps ;
@@ -56,11 +58,11 @@ public static IEnumerable<T> LoadRelatedData<T>(IEnumerable<T> values, IncludeSp
5658
5759 if ( nav . IsCollection ( ) )
5860 {
59- foreach ( T obj in values )
61+ foreach ( object obj in values )
6062 {
6163 object [ ] objValues = objProps . Select ( x => x . GetClrValue ( obj ) ) . ToArray ( ) ;
6264
63- valueSetter . SetClrValue ( obj , cache . Filter ( t . ClrType , x =>
65+ IList rValues = cache . Filter ( t . ClrType , x =>
6466 {
6567 int result = 0 ;
6668
@@ -78,12 +80,19 @@ public static IEnumerable<T> LoadRelatedData<T>(IEnumerable<T> values, IncludeSp
7880 }
7981
8082 return result == refValues . Count ( ) ;
81- } ) ) ;
83+ } ) ;
84+
85+ if ( navs . Count ( ) > 1 )
86+ {
87+ rValues = LoadData ( rValues , navs . Skip ( 1 ) ) ;
88+ }
89+
90+ valueSetter . SetClrValue ( obj , rValues ) ;
8291 }
8392 }
8493 else
8594 {
86- foreach ( T obj in values )
95+ foreach ( object obj in values )
8796 {
8897 object [ ] objValues = objProps . Select ( x => x . GetClrValue ( obj ) ) . ToArray ( ) ;
8998
@@ -109,13 +118,25 @@ public static IEnumerable<T> LoadRelatedData<T>(IEnumerable<T> values, IncludeSp
109118
110119 if ( matching . Count > 0 )
111120 {
112- valueSetter . SetClrValue ( obj , matching [ 0 ] ) ;
121+ object value = matching [ 0 ] ;
122+
123+ if ( navs . Count ( ) > 1 )
124+ {
125+ value = LoadData ( new object [ ] { value } , navs . Skip ( 1 ) ) [ 0 ] ;
126+ }
127+
128+ valueSetter . SetClrValue ( obj , value ) ;
113129 }
114130 }
115131 }
116132 }
117133
118134 return values ;
119135 }
136+
137+ public static IEnumerable < T > LoadRelatedData < T > ( IEnumerable < T > values , IncludeSpecification includeSpecification )
138+ {
139+ return LoadData ( values . ToList ( ) , includeSpecification . NavigationPath ) . Cast < T > ( ) ;
140+ }
120141 }
121142}
0 commit comments