Browse files

added fix for nested array contains.

  • Loading branch information...
1 parent 969069f commit 485801d835eae34c72770c363372abf6f82cd232 @craiggwilson craiggwilson committed with lanwin Nov 6, 2010
View
14 source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryProviderTests.cs
@@ -153,6 +153,20 @@ public void LocalList_Contains()
}
[Test]
+ public void NestedArray_Contains()
+ {
+ var people = from p in Collection.Linq()
+ where p.EmployerIds.Contains(1)
+ select p;
+
+ var queryObject = ((IMongoQueryable)people).GetQueryObject();
+ Assert.AreEqual(0, queryObject.Fields.Count);
+ Assert.AreEqual(0, queryObject.NumberToLimit);
+ Assert.AreEqual(0, queryObject.NumberToSkip);
+ Assert.AreEqual(new Document("EmployerIds", 1), queryObject.Query);
+ }
+
+ [Test]
public void NestedArray_Length()
{
var people = from p in Collection.Linq()
View
22 source/MongoDB/Linq/Translators/DocumentFormatter.cs
@@ -243,6 +243,28 @@ protected override Expression VisitMethodCall(MethodCallExpression m)
return m;
}
}
+ else if (m.Method.DeclaringType.IsArray)
+ {
+ if (m.Method.Name == "Contains")
+ {
+ field = m.Object as FieldExpression;
+ if (field != null)
+ {
+ VisitPredicate(field, true);
+ AddCondition(EvaluateConstant<object>(m.Arguments[0]));
+ PopConditionScope();
+ return m;
+ }
+
+ field = m.Arguments[0] as FieldExpression;
+ if (field == null)
+ throw new InvalidQueryException("A mongo field must be a part of the Contains method.");
+ VisitPredicate(field, true);
+ AddCondition("$in", EvaluateConstant<IEnumerable>(m.Object));
+ PopConditionScope();
+ return m;
+ }
+ }
throw new NotSupportedException(string.Format("The method {0} is not supported.", m.Method.Name));
}

0 comments on commit 485801d

Please sign in to comment.