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

Support Select new BsonDocument

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 3.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • Dotnet Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Issue:

      When trying to use .Select() where the lambda body is a new Dictionary<string,object> or new BsonDocument, the following error is observed:

      System.InvalidOperationException
      When called from 'VisitListInit', rewriting a node of type 'System.Linq.Expressions.NewExpression' must return a non-null value of the same type. Alternatively, override 'VisitListInit' and change it to not visit children of this type.
      

      The original Visit() call occurs in PartialEvaluator.cs.

      Repro:

         [Fact]
          public void Select_Bson_objField_should_work()
          {
              var collection = GetCollection(LinqProvider.V3);
      
              var queryable = collection.AsQueryable()
                  .Select(x => new BsonDocument
                  {
                      { "a", x.A }
                  });
      
              var stages = Translate(collection, queryable);
      
              var dt = queryable.ToList();
          }
      
          [Fact]
          public void Select_Dict_obj_should_work()
          {
              var collection = GetCollection(LinqProvider.V3);
      
              var queryable = collection.AsQueryable()
                  .Select(x => new Dictionary<string, object>
                  {
                      { "a", x }
                  });
      
              var stages = Translate(collection, queryable);
      
              var dt = queryable.ToList();
          }
      
          private class C
          {
              public int A { get; set; }
          }
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            jania.vandevoorde@mongodb.com Jania Vandevoorde (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: