Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed issue 19 in a roundabout way.

  • Loading branch information...
commit de04140c4d0b9a6a9639f318eefc0808fd399d4d 1 parent 2802698
@craiggwilson craiggwilson authored lanwin committed
View
46 source/MongoDB.Tests/Issues/Issue19.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using NUnit.Framework;
+using MongoDB.Attributes;
+using MongoDB.Configuration;
+
+namespace MongoDB.Issues
+{
+ [TestFixture]
+ public class Issue19
+ {
+ private class Post
+ {
+ [MongoId]
+ public Guid Id { get; set; }
+
+ public DateTime LastAccess { get; set; }
+ public List<string> Tags { get; set; }
+ }
+
+ [Test]
+ public void Should_return_an_empty_list()
+ {
+ var SearchTags = new List<string> { "test" };
+ using (var mongo = new Mongo())
+ {
+ mongo.Connect();
+ var db = mongo.GetDatabase("posts");
+ var posts = db.GetCollection<Post>();
+ posts.Remove(x => true);
+ posts.Insert(new Post() { Tags = new List<string> { "test", "funny" } });
+
+ var result = SearchTags
+ .Aggregate(posts.Linq(), (current, tag) => current.Where(x => x.Tags.Contains(tag)))
+ .OrderByDescending(x => x.LastAccess)
+ .ToList();
+
+ Assert.AreEqual(1, result.Count);
+ }
+ }
+
+ }
+}
View
1  source/MongoDB.Tests/MongoDB.Tests.csproj
@@ -94,6 +94,7 @@
<Compile Include="IntegrationTests\SecondServer\TestPooledConnectionFactory.cs" />
<Compile Include="IntegrationTests\Linq\LinqDomain.cs" />
<Compile Include="IntegrationTests\Linq\MapReduceTests.cs" />
+ <Compile Include="Issues\Issue19.cs" />
<Compile Include="UnitTests\Bson\BsonTestBase.cs" />
<Compile Include="UnitTests\Bson\TestBsonBinary.cs" />
<Compile Include="UnitTests\Bson\TestRoundTrips.cs" />
View
24 source/MongoDB/Linq/Translators/DocumentFormatter.cs
@@ -183,12 +183,24 @@ protected override Expression VisitMethodCall(MethodCallExpression m)
{
case "Contains":
field = m.Arguments[0] as FieldExpression;
- if (field == null)
- throw new InvalidQueryException(string.Format("The mongo field must be the argument in method {0}.", m.Method.Name));
- VisitPredicate(field, true);
- AddCondition("$in", EvaluateConstant<IEnumerable>(m.Object).OfType<object>().ToArray());
- PopConditionScope();
- return m;
+ if (field != null)
+ {
+ VisitPredicate(field, true);
+ AddCondition("$in", EvaluateConstant<IEnumerable>(m.Object).OfType<object>().ToArray());
+ PopConditionScope();
+ return m;
+ }
+
+ field = m.Object as FieldExpression;
+ if (field != null)
+ {
+ VisitPredicate(m.Object, true);
+ AddCondition(EvaluateConstant<object>(m.Arguments[0]));
+ PopConditionScope();
+ return m;
+ }
+
+ throw new InvalidQueryException(string.Format("The mongo field must be the argument in method {0}.", m.Method.Name));
}
}
else if (m.Method.DeclaringType == typeof(string))
Please sign in to comment.
Something went wrong with that request. Please try again.