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
    • Labels:
      None
    • Environment:
      VS 2019 Enterprise, W10, .NET Core 3.1 project.
    • Fully Compatible

      Take this Mongo class:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      _collection.Find(s => s.RelatedObjects.Any(o => o.Value == guid));
      _collection.Find(s => s.RelatedObjects.Select(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:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: