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

Linq Translation of Any in Where Filter Throw NotSupportedException

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.2, 2.8.0, 2.9.0, 2.10.0, 2.11.2
    • Component/s: Builders
    • None
    • Environment:
      .Net Core 3.1
      MongoDB Server 4.4.1, MongoDB Server 4.0.19, MongoDB Server 4.2.2

       

      I trying to find documents with filter below

       var filter = builder.Where(t => t.Array1.Any(l => !string.IsNullOrEmpty(model.ExternalId) && 
       l.ExternalId == model.ExternalId || 
       l.Name.ToLower() == model.Name.ToLower() ||
       t.Address.ToLower() == model.Address.ToLower()));

      But in result got an error 

      System.NotSupportedException: The LINQ expression: {document}{Locations}.Where((((False AndAlso ({document}{ExternalId} == null)) OrElse ({document}{Name}.ToLower() == "loc")) OrElse ({document}{Address}.ToLower() == "address"))) has the member "t" which can not be used to build a correct MongoDB query.
      

      On Driver version 2.7.2, .NetCore 2.1 and MongoDB Server 4.2 it works fine.

      It seems to be related to CSHARP-2705 but not sure how to fix it.

       

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            lefka.velchenko.work@gmail.com Oleksii Velchenko
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: