Unable to select KeyValuePair Key when using camelCase convention

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 3.4.1
    • Affects Version/s: 3.4.0
    • Component/s: LINQ3
    • 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?
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      3.4.0 introduced a bug that prevents the Key field of a KVP from being selected when using camelCase.

       

       

      
      

      System.FormatException: 'Element 'Key' does not match any field or property of class System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].'

       

       

       

       

      How to Reproduce

      using MongoDB.Bson.Serialization.Conventions;
      using MongoDB.Driver;
      using MongoDB.Driver.Linq;
      var defaultPack = new ConventionPack { new CamelCaseElementNameConvention() };
      ConventionRegistry.Register("camelCase", defaultPack, c => true);
      var client = new MongoClient("mongodb://localhost:27017");
      var collection = client.GetDatabase("kvp_bug").GetCollection<Person>(nameof(Person));
      await collection.InsertOneAsync(new Person() { Title = "Other" });
      await collection
          .AsQueryable()
          .GroupBy(x => x.Title)
          .Select(b => new KeyValuePair<string, int>(b.Key, b.Count()))
          .ToListAsync();
      public class Person
      {
          public string Title { get; set; }
      }
      
      
      

      I believe it's caused by NewKeyValuePairExpressionToAggregationExpressionTranslator.cs hardcoding the Key member which was introduced by https://github.com/mongodb/mongo-csharp-driver/pull/1661.

            Assignee:
            Oleksandr Poliakov
            Reporter:
            Sean Godsell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: