@@ -48,6 +48,8 @@ public class C
48
48
public int Y { get ; set ; }
49
49
[ BsonElement ( "d" ) ]
50
50
public D D { get ; set ; }
51
+ [ BsonElement ( "da" ) ]
52
+ public List < D > DA { get ; set ; }
51
53
[ BsonElement ( "s" ) ]
52
54
[ BsonIgnoreIfNull ]
53
55
public string S { get ; set ; }
@@ -149,11 +151,11 @@ public void Setup()
149
151
150
152
// documents inserted deliberately out of order to test sorting
151
153
_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 } } ) ;
153
155
_collection . Insert ( new C { Id = _id1 , X = 1 , Y = 11 , D = new D { Z = 11 } , S = "abc" , SA = new string [ ] { "Tom" , "Dick" , "Harry" } } ) ;
154
156
_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 } } ) ;
155
157
_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 } } } ) ;
157
159
}
158
160
159
161
[ Test ]
@@ -1939,13 +1941,27 @@ where c.A.Any()
1939
1941
}
1940
1942
1941
1943
[ 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 ." ) ]
1943
1945
public void TestWhereAAnyWithPredicate ( )
1944
1946
{
1945
1947
var query = from c in _collection . AsQueryable < C > ( )
1946
1948
where c . A . Any ( a => a > 3 )
1947
1949
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 ) ) ;
1949
1965
}
1950
1966
1951
1967
[ Test ]
@@ -3033,6 +3049,29 @@ public void TestWhereDNotEquals11Not()
3033
3049
Assert . AreEqual ( 1 , Consume ( query ) ) ;
3034
3050
}
3035
3051
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
+
3036
3075
[ Test ]
3037
3076
public void TestWhereEAContainsAll ( )
3038
3077
{
0 commit comments