@@ -117,6 +117,59 @@ public void OrderBy_Exceptions()
117
117
Assert . Throws < ArgumentException > ( ( ) => qry . OrderBy ( " " ) ) ;
118
118
}
119
119
120
+ /// <summary>
121
+ /// https://github.com/NArnott/System.Linq.Dynamic/issues/42 and https://github.com/StefH/System.Linq.Dynamic.Core/issues/18
122
+ /// </summary>
123
+ [ Fact ]
124
+ public void SelectMany_OverArray ( )
125
+ {
126
+ var testList = new [ ]
127
+ {
128
+ new [ ] { 1 } ,
129
+ new [ ] { 1 , 2 } ,
130
+ new [ ] { 1 , 2 , 3 } ,
131
+ new [ ] { 1 , 2 , 3 , 4 } ,
132
+ new [ ] { 1 , 2 , 3 , 4 , 5 }
133
+ } ;
134
+
135
+ var expectedResult = testList . SelectMany ( it => it ) . ToList ( ) ;
136
+ var result = testList . AsQueryable ( ) . SelectMany ( "it" ) . ToDynamicList < int > ( ) ;
137
+
138
+ Assert . Equal ( expectedResult , result ) ;
139
+ }
140
+
141
+ [ Fact ]
142
+ public void SelectMany_OverArray_TResult ( )
143
+ {
144
+ var testList = new [ ]
145
+ {
146
+ new [ ] { new Permission { Name = "p-Admin" } } ,
147
+ new [ ] { new Permission { Name = "p-Admin" } , new Permission { Name = "p-User" } } ,
148
+ new [ ] { new Permission { Name = "p-x" } , new Permission { Name = "p-y" } }
149
+ } ;
150
+
151
+ var expectedResult = testList . SelectMany ( it => it ) . ToList ( ) ;
152
+ var result = testList . AsQueryable ( ) . SelectMany < Permission > ( "it" ) . ToList ( ) ;
153
+
154
+ Assert . Equal ( expectedResult , result ) ;
155
+ }
156
+
157
+ [ Fact ]
158
+ public void SelectMany_OverArray_IntoType ( )
159
+ {
160
+ var testList = new [ ]
161
+ {
162
+ new [ ] { new Permission { Name = "p-Admin" } } ,
163
+ new [ ] { new Permission { Name = "p-Admin" } , new Permission { Name = "p-User" } } ,
164
+ new [ ] { new Permission { Name = "p-x" } , new Permission { Name = "p-y" } }
165
+ } ;
166
+
167
+ var expectedResult = testList . SelectMany ( it => it ) . ToList ( ) ;
168
+ var result = testList . AsQueryable ( ) . SelectMany ( typeof ( Permission ) , "it" ) . ToDynamicList < Permission > ( ) ;
169
+
170
+ Assert . Equal ( expectedResult , result ) ;
171
+ }
172
+
120
173
[ Fact ]
121
174
public void SelectMany ( )
122
175
{
@@ -156,8 +209,7 @@ public void SelectMany_TResult()
156
209
new Role
157
210
{
158
211
Name = "Admin" ,
159
- Permissions =
160
- new List < Permission > { new Permission { Name = "p-Admin" } , new Permission { Name = "p-User" } }
212
+ Permissions = new List < Permission > { new Permission { Name = "p-Admin" } , new Permission { Name = "p-User" } }
161
213
}
162
214
} ;
163
215
users [ 1 ] . Roles = new List < Role >
@@ -176,7 +228,7 @@ public void SelectMany_TResult()
176
228
}
177
229
178
230
[ Fact ]
179
- public void SelectMany_Intotype ( )
231
+ public void SelectMany_IntoType ( )
180
232
{
181
233
// Act
182
234
var users = User . GenerateSampleModels ( 2 ) ;
@@ -185,8 +237,7 @@ public void SelectMany_Intotype()
185
237
new Role
186
238
{
187
239
Name = "Admin" ,
188
- Permissions =
189
- new List < Permission > { new Permission { Name = "p-Admin" } , new Permission { Name = "p-User" } }
240
+ Permissions = new List < Permission > { new Permission { Name = "p-Admin" } , new Permission { Name = "p-User" } }
190
241
}
191
242
} ;
192
243
users [ 1 ] . Roles = new List < Role >
@@ -198,7 +249,7 @@ public void SelectMany_Intotype()
198
249
199
250
// Assign
200
251
var queryNormal = query . SelectMany ( u => u . Roles . SelectMany ( r => r . Permissions ) ) . ToList ( ) ;
201
- var queryDynamic = query . SelectMany ( typeof ( Permission ) , "Roles.SelectMany(Permissions)" ) . ToDynamicList ( ) ;
252
+ var queryDynamic = query . SelectMany ( typeof ( Permission ) , "Roles.SelectMany(Permissions)" ) . ToDynamicList ( ) ;
202
253
203
254
// Assert
204
255
Assert . Equal ( queryNormal , queryDynamic ) ;
@@ -208,37 +259,37 @@ public void SelectMany_Intotype()
208
259
public void SelectMany_WithResultProjection ( )
209
260
{
210
261
//Arrange
211
- List < int > rangeOfInt = new List < int > { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
212
- List < double > rangeOfDouble = new List < double > { 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 , 9.0 , 10.0 } ;
262
+ List < int > rangeOfInt = new List < int > { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
263
+ List < double > rangeOfDouble = new List < double > { 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 , 9.0 , 10.0 } ;
213
264
List < KeyValuePair < int , double > > range =
214
265
rangeOfInt . SelectMany ( e => rangeOfDouble , ( x , y ) => new KeyValuePair < int , double > ( x , y ) ) . ToList ( ) ;
215
266
216
267
//Act
217
268
IEnumerable rangeResult = rangeOfInt . AsQueryable ( )
218
- . SelectMany ( "@0" , "new(x as _A, y as _B)" , new object [ ] { rangeOfDouble } )
269
+ . SelectMany ( "@0" , "new(x as _A, y as _B)" , new object [ ] { rangeOfDouble } )
219
270
. Select ( "it._A * it._B" ) ;
220
271
221
272
//Assert
222
- Assert . Equal ( range . Select ( t => t . Key * t . Value ) . ToArray ( ) , rangeResult . Cast < double > ( ) . ToArray ( ) ) ;
273
+ Assert . Equal ( range . Select ( t => t . Key * t . Value ) . ToArray ( ) , rangeResult . Cast < double > ( ) . ToArray ( ) ) ;
223
274
}
224
275
225
276
[ Fact ]
226
277
public void SelectMany_WithResultProjection_CustomParameterNames ( )
227
278
{
228
279
//Arrange
229
- List < int > rangeOfInt = new List < int > { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
230
- List < double > rangeOfDouble = new List < double > { 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 , 9.0 , 10.0 } ;
280
+ List < int > rangeOfInt = new List < int > { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
281
+ List < double > rangeOfDouble = new List < double > { 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 , 9.0 , 10.0 } ;
231
282
List < KeyValuePair < int , double > > range =
232
283
rangeOfInt . SelectMany ( e => rangeOfDouble , ( x , y ) => new KeyValuePair < int , double > ( x , y ) ) . ToList ( ) ;
233
284
234
285
//Act
235
286
IEnumerable rangeResult = rangeOfInt . AsQueryable ( )
236
287
. SelectMany ( "@0" , "new(VeryNiceName as _A, OtherName as _X)" , "VeryNiceName" , "OtherName" ,
237
- new object [ ] { rangeOfDouble } )
288
+ new object [ ] { rangeOfDouble } )
238
289
. Select ( "it._A * it._X" ) ;
239
290
240
291
//Assert
241
- Assert . Equal ( range . Select ( t => t . Key * t . Value ) . ToArray ( ) , rangeResult . Cast < double > ( ) . ToArray ( ) ) ;
292
+ Assert . Equal ( range . Select ( t => t . Key * t . Value ) . ToArray ( ) , rangeResult . Cast < double > ( ) . ToArray ( ) ) ;
242
293
}
243
294
244
295
[ Fact ]
@@ -280,7 +331,7 @@ public void Select_PropertyVisitor_QueryInterceptor()
280
331
public void Select_TResult ( )
281
332
{
282
333
//Arrange
283
- List < int > range = new List < int > { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
334
+ List < int > range = new List < int > { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
284
335
var testList = User . GenerateSampleModels ( 100 ) ;
285
336
var qry = testList . AsQueryable ( ) ;
286
337
@@ -290,7 +341,7 @@ public void Select_TResult()
290
341
var userProfiles = qry . Select < UserProfile > ( "Profile" ) . ToList ( ) ;
291
342
292
343
//Assert
293
- Assert . Equal ( range . Select ( x => x * x ) . ToList ( ) , rangeResult ) ;
344
+ Assert . Equal ( range . Select ( x => x * x ) . ToList ( ) , rangeResult ) ;
294
345
Assert . Equal ( testList . Select ( x => x . UserName ) . ToList ( ) , userNames ) ;
295
346
Assert . Equal ( testList . Select ( x => x . Profile ) . ToList ( ) , userProfiles ) ;
296
347
}
@@ -299,17 +350,17 @@ public void Select_TResult()
299
350
public void Select_IntoType ( )
300
351
{
301
352
//Arrange
302
- List < int > range = new List < int > { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
353
+ List < int > range = new List < int > { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
303
354
var testList = User . GenerateSampleModels ( 10 ) ;
304
355
var qry = testList . AsQueryable ( ) ;
305
356
306
357
//Act
307
- IEnumerable rangeResult = range . AsQueryable ( ) . Select ( typeof ( int ) , "it * it" ) ;
308
- var userNames = qry . Select ( typeof ( string ) , "UserName" ) ;
309
- var userProfiles = qry . Select ( typeof ( UserProfile ) , "Profile" ) ;
358
+ IEnumerable rangeResult = range . AsQueryable ( ) . Select ( typeof ( int ) , "it * it" ) ;
359
+ var userNames = qry . Select ( typeof ( string ) , "UserName" ) ;
360
+ var userProfiles = qry . Select ( typeof ( UserProfile ) , "Profile" ) ;
310
361
311
362
//Assert
312
- Assert . Equal ( range . Select ( x => x * x ) . Cast < object > ( ) . ToList ( ) , rangeResult . ToDynamicList ( ) ) ;
363
+ Assert . Equal ( range . Select ( x => x * x ) . Cast < object > ( ) . ToList ( ) , rangeResult . ToDynamicList ( ) ) ;
313
364
Assert . Equal ( testList . Select ( x => x . UserName ) . Cast < object > ( ) . ToList ( ) , userNames . ToDynamicList ( ) ) ;
314
365
Assert . Equal ( testList . Select ( x => x . Profile ) . Cast < object > ( ) . ToList ( ) , userProfiles . ToDynamicList ( ) ) ;
315
366
}
@@ -318,7 +369,7 @@ public void Select_IntoType()
318
369
public void Select ( )
319
370
{
320
371
//Arrange
321
- List < int > range = new List < int > { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
372
+ List < int > range = new List < int > { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ;
322
373
var testList = User . GenerateSampleModels ( 100 ) ;
323
374
var qry = testList . AsQueryable ( ) ;
324
375
@@ -329,7 +380,7 @@ public void Select()
329
380
var userRoles = qry . Select ( "new (UserName, Roles.Select(Id) AS RoleIds)" ) ;
330
381
331
382
//Assert
332
- Assert . Equal ( range . Select ( x => x * x ) . ToArray ( ) , rangeResult . Cast < int > ( ) . ToArray ( ) ) ;
383
+ Assert . Equal ( range . Select ( x => x * x ) . ToArray ( ) , rangeResult . Cast < int > ( ) . ToArray ( ) ) ;
333
384
334
385
#if NET35 || DNXCORE50 || DOTNET5_4 || DOTNET5_1 || UAP10_0
335
386
Assert . Equal ( testList . Select ( x => x . UserName ) . ToArray ( ) , userNames . AsEnumerable ( ) . Cast < string > ( ) . ToArray ( ) ) ;
@@ -396,12 +447,12 @@ public void GroupBy_Exceptions()
396
447
Assert . Throws < ParseException > ( ( ) => qry . GroupBy ( "new (Id, UserName" ) ) ;
397
448
Assert . Throws < ParseException > ( ( ) => qry . GroupBy ( "new (Id, UserName, Bad)" ) ) ;
398
449
399
- Assert . Throws < ArgumentNullException > ( ( ) => DynamicQueryable . GroupBy ( ( IQueryable < string > ) null , "Id" ) ) ;
450
+ Assert . Throws < ArgumentNullException > ( ( ) => DynamicQueryable . GroupBy ( ( IQueryable < string > ) null , "Id" ) ) ;
400
451
Assert . Throws < ArgumentNullException > ( ( ) => qry . GroupBy ( null ) ) ;
401
452
Assert . Throws < ArgumentException > ( ( ) => qry . GroupBy ( "" ) ) ;
402
453
Assert . Throws < ArgumentException > ( ( ) => qry . GroupBy ( " " ) ) ;
403
454
404
- Assert . Throws < ArgumentNullException > ( ( ) => qry . GroupBy ( "Id" , ( string ) null ) ) ;
455
+ Assert . Throws < ArgumentNullException > ( ( ) => qry . GroupBy ( "Id" , ( string ) null ) ) ;
405
456
Assert . Throws < ArgumentException > ( ( ) => qry . GroupBy ( "Id" , "" ) ) ;
406
457
Assert . Throws < ArgumentException > ( ( ) => qry . GroupBy ( "Id" , " " ) ) ;
407
458
}
@@ -463,17 +514,17 @@ private class Pet
463
514
public void Join ( )
464
515
{
465
516
//Arrange
466
- Person magnus = new Person { Name = "Hedlund, Magnus" } ;
467
- Person terry = new Person { Name = "Adams, Terry" } ;
468
- Person charlotte = new Person { Name = "Weiss, Charlotte" } ;
517
+ Person magnus = new Person { Name = "Hedlund, Magnus" } ;
518
+ Person terry = new Person { Name = "Adams, Terry" } ;
519
+ Person charlotte = new Person { Name = "Weiss, Charlotte" } ;
469
520
470
- Pet barley = new Pet { Name = "Barley" , Owner = terry } ;
471
- Pet boots = new Pet { Name = "Boots" , Owner = terry } ;
472
- Pet whiskers = new Pet { Name = "Whiskers" , Owner = charlotte } ;
473
- Pet daisy = new Pet { Name = "Daisy" , Owner = magnus } ;
521
+ Pet barley = new Pet { Name = "Barley" , Owner = terry } ;
522
+ Pet boots = new Pet { Name = "Boots" , Owner = terry } ;
523
+ Pet whiskers = new Pet { Name = "Whiskers" , Owner = charlotte } ;
524
+ Pet daisy = new Pet { Name = "Daisy" , Owner = magnus } ;
474
525
475
- List < Person > people = new List < Person > { magnus , terry , charlotte } ;
476
- List < Pet > pets = new List < Pet > { barley , boots , whiskers , daisy } ;
526
+ List < Person > people = new List < Person > { magnus , terry , charlotte } ;
527
+ List < Pet > pets = new List < Pet > { barley , boots , whiskers , daisy } ;
477
528
478
529
479
530
//Act
@@ -482,7 +533,7 @@ public void Join()
482
533
person => person ,
483
534
pet => pet . Owner ,
484
535
( person , pet ) =>
485
- new { OwnerName = person . Name , Pet = pet . Name } ) ;
536
+ new { OwnerName = person . Name , Pet = pet . Name } ) ;
486
537
487
538
var dynamicQuery = people . AsQueryable ( ) . Join (
488
539
pets ,
0 commit comments