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

Support BsonDocument and BsonArray in LINQ queries.

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.14.0
    • Affects Version/s: None
    • Component/s: LINQ3
    • None

      Given a Collection<BsonDocument>, LINQ3 queries using doc["FieldName"] syntax fail with the following exception:

      Unhandled Exception: MongoDB.Driver.Linq.Linq3Implementation.ExpressionNotSupportedException: Expression not supported: doc.get_Item("FieldName").
       

      The same query works in LINQ2 using doc["FieldName"] or in LINQ3 with a POCO using doc.FieldName.

      Full repro:

      using System;
      using MongoDB.Bson;
      using MongoDB.Driver;
      using MongoDB.Driver.Linq;
      
      var settings = new MongoClientSettings { LinqProvider = LinqProvider.V3 };
      var client = new MongoClient(settings);
      var db = client.GetDatabase("test");
      var coll = db.GetCollection<BsonDocument>("coll");
      
      var query = coll.AsQueryable().Where(doc => doc["createdAt"] == DateTime.Now);
      foreach (var doc in query.ToList())
      {
          Console.WriteLine(doc);
      }
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            james.kovacs@mongodb.com James Kovacs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: