Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-468

Any() query on subdocument inside of Where() throws exception

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.4.2
    • Component/s: None
    • None

      Given these entities:

      public class Person
      {
      public Guid Id

      { get; set; }
      public string Name { get; set; }

      public List<Address> Addresses

      { get; set; }
      }

      public class Address
      {
      public string Street { get; set; }

      public string City

      { get; set; }
      public string State { get; set; }

      public string Zip

      { get; set; }

      }

      This query does not work: (people = MongoCollection<Person>)
      people.AsQueryable().Where(p => p.Addresses.Any(a => a.State == "NY")).ToList()

      It would be the equivalent of this query in the shell:
      db.people.find(

      {"Addresses.State":"NY"}

      )

      The exception thrown is:
      Unhandled Exception: System.NotSupportedException: Enumerable.Any with a predicate is not supported.
      at MongoDB.Driver.Linq.SelectQuery.BuildAnyQuery(MethodCallExpression methodCallExpression) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:line 262
      at MongoDB.Driver.Linq.SelectQuery.BuildMethodCallQuery(MethodCallExpression methodCallExpression) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:line 695
      at MongoDB.Driver.Linq.SelectQuery.BuildQuery(Expression expression) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:line 832
      at MongoDB.Driver.Linq.SelectQuery.BuildQuery() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:line 123
      at MongoDB.Driver.Linq.SelectQuery.Execute() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:line 132
      at MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\MongoQueryProvider.cs:line 147
      at MongoDB.Driver.Linq.MongoQueryable`1.GetEnumerator() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\MongoQueryable.cs:line 81
      at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
      at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
      at ConsoleApplication5.Program.Main(String[] args) in C:\Projects\ConsoleApplication5\ConsoleApplication5\Program.cs:line 55

      For now, I am using the Inject() workaround, however this type of query I believe needs to be supported.

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            rhoffman Ryan Hoffman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: