@@ -48,6 +48,8 @@ public class C
4848 public int Y { get ; set ; }
4949 [ BsonElement ( "d" ) ]
5050 public D D { get ; set ; }
51+ [ BsonElement ( "da" ) ]
52+ public List < D > DA { get ; set ; }
5153 [ BsonElement ( "s" ) ]
5254 [ BsonIgnoreIfNull ]
5355 public string S { get ; set ; }
@@ -149,11 +151,11 @@ public void Setup()
149151
150152 // documents inserted deliberately out of order to test sorting
151153 _collection . Drop ( ) ;
152- _collection . Insert ( new C { Id = _id2 , X = 2 , Y = 11 , D = new D { Z = 22 } , A = new [ ] { 2 , 3 , 4 } , L = new List < int > { 2 , 3 , 4 } } ) ;
154+ _collection . Insert ( new C { Id = _id2 , X = 2 , Y = 11 , D = new D { Z = 22 } , A = new [ ] { 2 , 3 , 4 } , DA = new List < D > { new D { Z = 111 } , new D { Z = 222 } } , L = new List < int > { 2 , 3 , 4 } } ) ;
153155 _collection . Insert ( new C { Id = _id1 , X = 1 , Y = 11 , D = new D { Z = 11 } , S = "abc" , SA = new string [ ] { "Tom" , "Dick" , "Harry" } } ) ;
154156 _collection . Insert ( new C { Id = _id3 , X = 3 , Y = 33 , D = new D { Z = 33 } , B = true , BA = new bool [ ] { true } , E = E . A , EA = new E [ ] { E . A , E . B } } ) ;
155157 _collection . Insert ( new C { Id = _id5 , X = 5 , Y = 44 , D = new D { Z = 55 } , DBRef = new MongoDBRef ( "db" , "c" , 1 ) } ) ;
156- _collection . Insert ( new C { Id = _id4 , X = 4 , Y = 44 , D = new D { Z = 44 } , S = " xyz " } ) ;
158+ _collection . Insert ( new C { Id = _id4 , X = 4 , Y = 44 , D = new D { Z = 44 } , S = " xyz " , DA = new List < D > { new D { Z = 333 } , new D { Z = 444 } } } ) ;
157159 }
158160
159161 [ Test ]
@@ -1939,13 +1941,27 @@ where c.A.Any()
19391941 }
19401942
19411943 [ Test ]
1942- [ ExpectedException ( typeof ( NotSupportedException ) , ExpectedMessage = "Enumerable. Any with a predicate is not supported ." ) ]
1944+ [ ExpectedException ( typeof ( NotSupportedException ) , ExpectedMessage = "Any is only support for items that serialize into documents. The current serializer is BsonSerializationInfo and must implement IBsonMemberSerializationInfoProvider for participation in Any queries ." ) ]
19431945 public void TestWhereAAnyWithPredicate ( )
19441946 {
19451947 var query = from c in _collection . AsQueryable < C > ( )
19461948 where c . A . Any ( a => a > 3 )
19471949 select c ;
1948- query . ToList ( ) ; // execute query
1950+
1951+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
1952+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
1953+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
1954+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
1955+
1956+ var selectQuery = ( SelectQuery ) translatedQuery ;
1957+ Assert . AreEqual ( "(C c) => Enumerable.Any<Int32>(c.A, (Int32 a) => (a > 3))" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
1958+ Assert . IsNull ( selectQuery . OrderBy ) ;
1959+ Assert . IsNull ( selectQuery . Projection ) ;
1960+ Assert . IsNull ( selectQuery . Skip ) ;
1961+ Assert . IsNull ( selectQuery . Take ) ;
1962+
1963+ Assert . AreEqual ( "{ \" a\" : 2 }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
1964+ Assert . AreEqual ( 1 , Consume ( query ) ) ;
19491965 }
19501966
19511967 [ Test ]
@@ -3033,6 +3049,29 @@ public void TestWhereDNotEquals11Not()
30333049 Assert . AreEqual ( 1 , Consume ( query ) ) ;
30343050 }
30353051
3052+ [ Test ]
3053+ public void TestWhereDAAnyWithPredicate ( )
3054+ {
3055+ var query = from c in _collection . AsQueryable < C > ( )
3056+ where c . DA . Any ( x => x . Z == 333 )
3057+ select c ;
3058+
3059+ var translatedQuery = MongoQueryTranslator . Translate ( query ) ;
3060+ Assert . IsInstanceOf < SelectQuery > ( translatedQuery ) ;
3061+ Assert . AreSame ( _collection , translatedQuery . Collection ) ;
3062+ Assert . AreSame ( typeof ( C ) , translatedQuery . DocumentType ) ;
3063+
3064+ var selectQuery = ( SelectQuery ) translatedQuery ;
3065+ Assert . AreEqual ( "(C c) => Enumerable.Any<D>(c.DA, (D x) => (x.Z == 333))" , ExpressionFormatter . ToString ( selectQuery . Where ) ) ;
3066+ Assert . IsNull ( selectQuery . OrderBy ) ;
3067+ Assert . IsNull ( selectQuery . Projection ) ;
3068+ Assert . IsNull ( selectQuery . Skip ) ;
3069+ Assert . IsNull ( selectQuery . Take ) ;
3070+
3071+ Assert . AreEqual ( "{ \" da\" : { \" $elemMatch\" : { \" z\" : 333 } } }" , selectQuery . BuildQuery ( ) . ToJson ( ) ) ;
3072+ Assert . AreEqual ( 1 , Consume ( query ) ) ;
3073+ }
3074+
30363075 [ Test ]
30373076 public void TestWhereEAContainsAll ( )
30383077 {
0 commit comments