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

NotSupportedException when using Contains() to Filter Embedded Documents

    • Type: Icon: New Feature New Feature
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Linq
    • None

      reproduce code

      var result = postCollection
          .AsQueryable()
          .Select(p => new
          {
              Id = p.Id,
              Comments = p.Comments.Where(c => c.Text.Contains("test"))
          })
          .ToList();
      Message: System.NotSupportedException : Contains of type System.String is not supported in the expression tree {document}{$c.Text}.Contains("test"). Stack Trace: AggregateLanguageTranslator.TranslateMethodCall(MethodCallExpression node) AggregateLanguageTranslator.TranslateValue(Expression node) AggregateLanguageTranslator.TranslateWhere(WhereExpression node) AggregateLanguageTranslator.TranslateValue(Expression node) AggregateLanguageTranslator.TranslatePipeline(PipelineExpression node) AggregateLanguageTranslator.TranslateValue(Expression node) AggregateLanguageTranslator.TranslateMapping(ProjectionMapping mapping) AggregateLanguageTranslator.TranslateNew(NewExpression node) AggregateLanguageTranslator.TranslateValue(Expression node) AggregateLanguageTranslator.Translate(Expression node, ExpressionTranslationOptions translationOptions) QueryableTranslator.TranslateProjectValue(Expression selector) QueryableTranslator.TranslateSelect(SelectExpression node) QueryableTranslator.Translate(Expression node) QueryableTranslator.TranslatePipeline(PipelineExpression node) QueryableTranslator.Translate(Expression node) QueryableTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry, ExpressionTranslationOptions translationOptions) MongoQueryProviderImpl`1.Translate(Expression expression) MongoQueryProviderImpl`1.Execute(Expression expression) MongoQueryableImpl`2.GetEnumerator() List`1.ctor(IEnumerable`1 collection) Enumerable.ToList[TSource](IEnumerable`1 source)
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            mj.ebrahimi72@gmail.com Mohamad Javad Ebrahimi
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: