@@ -419,6 +419,20 @@ private bool TryBuildLinqMethodCall(MethodCallExpression node, out BsonValue res
419
419
result = null ;
420
420
switch ( node . Method . Name )
421
421
{
422
+ case "All" :
423
+ if ( TryBuildMap ( node , out result ) )
424
+ {
425
+ result = new BsonDocument ( "$allElementsTrue" , result ) ;
426
+ return true ;
427
+ }
428
+ break ;
429
+ case "Any" :
430
+ if ( TryBuildMap ( node , out result ) )
431
+ {
432
+ result = new BsonDocument ( "$anyElementTrue" , result ) ;
433
+ return true ;
434
+ }
435
+ break ;
422
436
case "Count" :
423
437
case "LongCount" :
424
438
if ( node . Arguments . Count == 1 )
@@ -450,29 +464,8 @@ private bool TryBuildLinqMethodCall(MethodCallExpression node, out BsonValue res
450
464
}
451
465
break ;
452
466
case "Select" :
453
- var sourceSerializationExpression = node . Arguments [ 0 ] as IBsonSerializationInfoExpression ;
454
- if ( sourceSerializationExpression != null )
467
+ if ( TryBuildMap ( node , out result ) )
455
468
{
456
- var lambda = MongoExpressionVisitor . GetLambda ( node . Arguments [ 1 ] ) ;
457
- if ( lambda . Body is IBsonSerializationInfoExpression )
458
- {
459
- result = ResolveValue ( lambda . Body ) ;
460
- return true ;
461
- }
462
-
463
- var inputValue = ResolveValue ( node . Arguments [ 0 ] ) ;
464
- var asValue = lambda . Parameters [ 0 ] . Name ;
465
-
466
- // HACK: need to add a leading $ sign to the replacement because of how we resolve values.
467
- var body = FieldNameReplacer . Replace ( lambda . Body , sourceSerializationExpression . SerializationInfo . ElementName , "$" + asValue ) ;
468
- var inValue = ResolveValue ( body ) ;
469
-
470
- result = new BsonDocument ( "$map" , new BsonDocument
471
- {
472
- { "input" , inputValue } ,
473
- { "as" , asValue } ,
474
- { "in" , inValue }
475
- } ) ;
476
469
return true ;
477
470
}
478
471
break ;
@@ -492,6 +485,38 @@ private bool TryBuildLinqMethodCall(MethodCallExpression node, out BsonValue res
492
485
return false ;
493
486
}
494
487
488
+ private bool TryBuildMap ( MethodCallExpression node , out BsonValue result )
489
+ {
490
+ result = null ;
491
+ var sourceSerializationExpression = node . Arguments [ 0 ] as IBsonSerializationInfoExpression ;
492
+ if ( sourceSerializationExpression != null )
493
+ {
494
+ var lambda = MongoExpressionVisitor . GetLambda ( node . Arguments [ 1 ] ) ;
495
+ if ( lambda . Body is IBsonSerializationInfoExpression )
496
+ {
497
+ result = ResolveValue ( lambda . Body ) ;
498
+ return true ;
499
+ }
500
+
501
+ var inputValue = ResolveValue ( node . Arguments [ 0 ] ) ;
502
+ var asValue = lambda . Parameters [ 0 ] . Name ;
503
+
504
+ // HACK: need to add a leading $ sign to the replacement because of how we resolve values.
505
+ var body = FieldNameReplacer . Replace ( lambda . Body , sourceSerializationExpression . SerializationInfo . ElementName , "$" + asValue ) ;
506
+ var inValue = ResolveValue ( body ) ;
507
+
508
+ result = new BsonDocument ( "$map" , new BsonDocument
509
+ {
510
+ { "input" , inputValue } ,
511
+ { "as" , asValue } ,
512
+ { "in" , inValue }
513
+ } ) ;
514
+ return true ;
515
+ }
516
+
517
+ return false ;
518
+ }
519
+
495
520
private bool TryBuildStringMethodCall ( MethodCallExpression node , out BsonValue result )
496
521
{
497
522
result = null ;
0 commit comments