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

LINQ3 projections unable to translate indexer access in IDictionary property

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

      Summary

      After updating to the latest version of the mongodb driver (2.19), which switched to the LINQ3 queryable provider, an existing query is throwing with the exception:

      MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: x.Dict.get_Item("test").    at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators.GetItemMethodToAggregationExpressionTranslator.Translate(TranslationContext context, MethodCallExpression expression)

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      MongoDBDriver 2.19.1, running against a local server version 6.0.5

      How to Reproduce

      Example console app:

      using MongoDB.Driver;
      using MongoDB.Driver.Linq;
      
      var Query = (LinqProvider provider) =>
      {
          var connectionstring = "mongodb://docker:mongopw@localhost:49153";
          var settings = MongoClientSettings.FromConnectionString(connectionstring);
          settings.LinqProvider = provider;
          var client = new MongoClient(settings);
          var db = client.GetDatabase("db1");
          var collection = db.GetCollection<ExampleClass>("collection1");
          return collection.AsQueryable().Select(x => x.Dict["test"]).First();
      };
      
      Console.WriteLine(Query(LinqProvider.V2)); // Works
      Console.WriteLine(Query(LinqProvider.V3)); // Throws exception
      
      class ExampleClass
      {
          public IDictionary<string, int> Dict { get; set; }
      }
      

      Additional Background

      Tried to do some investigation, from what I can tell, GetItemMethodToAggregationExpressionTranslator.Translate calls TryGetIDictionaryGenericInterface but there is no check that the `type` parameter itself is an `IDictionary` like `TryGetIEnumerableGenericInterface` does.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            6kzmr11h57yl@gmail.com Brandon N/A
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: