@@ -521,6 +521,11 @@ private IMongoQuery BuildContainsQuery(MethodCallExpression methodCallExpression
521
521
return BuildStringQuery ( methodCallExpression ) ;
522
522
}
523
523
524
+ if ( methodCallExpression . Object != null && methodCallExpression . Object . NodeType == ExpressionType . Constant )
525
+ {
526
+ return BuildInQuery ( methodCallExpression ) ;
527
+ }
528
+
524
529
BsonSerializationInfo serializationInfo = null ;
525
530
ConstantExpression valueExpression = null ;
526
531
var arguments = methodCallExpression . Arguments . ToArray ( ) ;
@@ -536,6 +541,10 @@ private IMongoQuery BuildContainsQuery(MethodCallExpression methodCallExpression
536
541
{
537
542
if ( methodCallExpression . Method . DeclaringType == typeof ( Enumerable ) )
538
543
{
544
+ if ( arguments [ 0 ] . NodeType == ExpressionType . Constant )
545
+ {
546
+ return BuildInQuery ( methodCallExpression ) ;
547
+ }
539
548
serializationInfo = GetSerializationInfo ( arguments [ 0 ] ) ;
540
549
valueExpression = arguments [ 1 ] as ConstantExpression ;
541
550
}
@@ -610,20 +619,46 @@ private IMongoQuery BuildEqualsQuery(MethodCallExpression methodCallExpression)
610
619
611
620
private IMongoQuery BuildInQuery ( MethodCallExpression methodCallExpression )
612
621
{
613
- if ( methodCallExpression . Method . DeclaringType == typeof ( LinqToMongo ) )
622
+ var methodDeclaringType = methodCallExpression . Method . DeclaringType ;
623
+ var arguments = methodCallExpression . Arguments . ToArray ( ) ;
624
+ BsonSerializationInfo serializationInfo = null ;
625
+ ConstantExpression valuesExpression = null ;
626
+ if ( methodDeclaringType == typeof ( LinqToMongo ) )
614
627
{
615
- var arguments = methodCallExpression . Arguments . ToArray ( ) ;
616
628
if ( arguments . Length == 2 )
617
629
{
618
- var serializationInfo = GetSerializationInfo ( arguments [ 0 ] ) ;
619
- var valuesExpression = arguments [ 1 ] as ConstantExpression ;
620
- if ( serializationInfo != null && valuesExpression != null )
621
- {
622
- var serializedValues = SerializeValues ( serializationInfo , ( IEnumerable ) valuesExpression . Value ) ;
623
- return Query . In ( serializationInfo . ElementName , serializedValues ) ;
624
- }
630
+ serializationInfo = GetSerializationInfo ( arguments [ 0 ] ) ;
631
+ valuesExpression = arguments [ 1 ] as ConstantExpression ;
625
632
}
626
633
}
634
+ else if ( methodDeclaringType == typeof ( Enumerable ) || methodDeclaringType == typeof ( Queryable ) )
635
+ {
636
+ if ( arguments . Length == 2 )
637
+ {
638
+ serializationInfo = GetSerializationInfo ( arguments [ 1 ] ) ;
639
+ valuesExpression = arguments [ 0 ] as ConstantExpression ;
640
+ }
641
+ }
642
+ else
643
+ {
644
+ if ( methodDeclaringType . IsGenericType )
645
+ {
646
+ methodDeclaringType = methodDeclaringType . GetGenericTypeDefinition ( ) ;
647
+ }
648
+
649
+ bool contains = methodDeclaringType . GetInterface ( "ICollection`1" ) != null ;
650
+ if ( contains && arguments . Length == 1 )
651
+ {
652
+ serializationInfo = GetSerializationInfo ( arguments [ 0 ] ) ;
653
+ valuesExpression = methodCallExpression . Object as ConstantExpression ;
654
+ }
655
+ }
656
+
657
+ if ( serializationInfo != null && valuesExpression != null )
658
+ {
659
+ var serializedValues = SerializeValues ( serializationInfo , ( IEnumerable ) valuesExpression . Value ) ;
660
+ return Query . In ( serializationInfo . ElementName , serializedValues ) ;
661
+ }
627
662
return null ;
628
663
}
629
664
0 commit comments