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

Aggregate().Project() with strongly typed class doesn't use ElementName

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.17.0
    • Affects Version/s: 2.14.0
    • Component/s: Builders, LINQ3
    • Labels:
      None

      Tested with version 2.14.1 and LINQ provider V2.

      Given the class:

       

      public class TestClass
      {
        [BsonElement("_p")]
        public string Property { get; set; }
      }

       

      This query:

       

      var queryable = collection.AsQueryable() .Select(x => new TestClass{ Property = x.Property.ToUpper() });
      

       

      is handled correctly and produces the following MQL request:

       

      { 
        "aggregate": "coll", 
        "pipeline": [{ 
          "$project": { 
            "_p": { "$toUpper": "$_p" }, 
            "_id": 0 } } ], 
        "cursor": {} }

       

      While this query: 

      collection.Aggregate()
        .Project(
          Builders<TestClass>.Projection
           .Expression(x => new TestClass { Property = x.Property.ToUpper() }));

      give the wrong query (still refers to attribute as Property:

       

      { 
        "aggregate": "coll", 
        "pipeline": [{ 
          "$project": { 
            "_p": { "$toUpper": "$_p" }, 
            "_id": 0 } } ], 
        "cursor": {} }   
      

       

       

       

       

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            a.daskos@thesignalgroup.com Antonios Daskos
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: