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

Support Select new Dictionary<string, object>

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Dotnet Drivers

      Issue:

      When trying to use .Select() where the lambda body is a new Dictionary<string,object>, 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_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:
            Unassigned Unassigned
            Reporter:
            jania.vandevoorde@mongodb.com Jania Vandevoorde (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: