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

Dictionary querying via LINQ Expression

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.10.3
    • Component/s: Linq
    • None
    • Environment:
      VS 2019 Enterprise, W10, .NET Core 3.1 project.
    • Fully Compatible
    • 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?

      Take this Mongo class:

      class ClassWithDictionary
      {
      	public IDictionary<string, Guid> RelatedObjects { get; set; }
      }
      

      Any kind of LINQ query on this dictionary seems to result into an exception. These all fail:

      _collection.Find(s => s.RelatedObjects.Any(o => o.Value == guid));
      _collection.Find(s => s.RelatedObjects.Any(o => o.Key == "Hello"));
      _collection.Find(s => s.RelatedObjects.Values.Any(o => o == guid));
      _collection.Find(s => s.RelatedObjects.Keys.Any(o => o == "Hello"));
      

      The exception:

      System.NotSupportedException: The expression tree is not supported: {document}{GerelateerdeObjecten}
         at MongoDB.Driver.Linq.Processors.EmbeddedPipeline.EmbeddedPipelineBinder.BindNonMethodCall(Expression node)
         at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.Bind(Expression node)
         at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.BindPipeline(Expression node)
         at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.BindMethodCall(MethodCallExpression node)
         at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.Bind(Expression node)
         at MongoDB.Driver.Linq.Processors.EmbeddedPipeline.EmbeddedPipelineBinder.Bind(Expression node, IBindingContext parent)
         at MongoDB.Driver.Linq.Processors.SerializationBinder.BindEmbeddedPipeline(MethodCallExpression node)
         at MongoDB.Driver.Linq.Processors.SerializationBinder.VisitMethodCall(MethodCallExpression node)
         at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
         at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
         at MongoDB.Driver.Linq.Processors.SerializationBinder.Visit(Expression node)
         at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
         at MongoDB.Driver.Linq.Processors.SerializationBinder.VisitBinary(BinaryExpression node)
         at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
         at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
         at MongoDB.Driver.Linq.Processors.SerializationBinder.Visit(Expression node)
         at MongoDB.Driver.Linq.Processors.SerializationBinder.Bind(Expression node, IBindingContext context, Boolean isClientSideProjection)
         at MongoDB.Driver.Linq.Processors.PipelineBindingContext.Bind(Expression node, Boolean isClientSideProjection)
         at MongoDB.Driver.Linq.Processors.PipelineBindingContext.Bind(Expression node)
         at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate[TDocument](Expression`1 predicate, IBsonSerializer`1 parameterSerializer, IBsonSerializerRegistry serializerRegistry)
         at MongoDB.Driver.ExpressionFilterDefinition`1.Render(IBsonSerializer`1 documentSerializer, IBsonSerializerRegistry serializerRegistry)
         at MongoDB.Driver.MongoCollectionImpl`1.CreateFindOperation[TProjection](FilterDefinition`1 filter, FindOptions`2 options)
         at MongoDB.Driver.MongoCollectionImpl`1.FindAsync[TProjection](IClientSessionHandle session, FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)
         at MongoDB.Driver.MongoCollectionImpl`1.<>c__DisplayClass43_0`1.<FindAsync>b__0(IClientSessionHandle session)
         at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
         at MongoDB.Driver.IAsyncCursorSourceExtensions.ToListAsync[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)   at MyMethod() 
      

      It seems only the default method ContainsKey works, but there is no way to query the values. Would it be possible to solve this issue?

      Thank you!

            Assignee:
            Unassigned Unassigned
            Reporter:
            bas.cantrijn@tsf.nl Bas C
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: