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

[Regression] Linq Translation of Nested Any throws NotSupportedException

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.8.0, 2.8.1, 2.9.0, 2.9.1, 2.10.0
    • Fix Version/s: 2.9.3
    • Component/s: Builders, Linq, Serialization
    • Labels:
      None

      Description

      Since 2.8.0, translation of LINQ query has broken for me - I now get a NotSupportedException, where before the query translated fine. The query I want is as below:

       

      {
          "$or": [
              {
                  "Invitees.Organisers": {
                      "$in": [
                          "Bob",
                          "John",
                          "Tim",
                          "Ryan"
                      ]
                  }
              },
              {
                  "Invitees.Roles": {
                      "$elemMatch": {
                          "k": {
                              "$in": [
                                  "Bob",
                                  "John",
                                  "Tim",
                                  "Ryan"
                              ]
                          },
                          "v": {
                              "$in": [
                                  "party_planning", "food_preparation"
                              ]
                          }
                      }
                  },
                  "Invitees.BlacklistRoles": {
                      "$not": {
                          "$elemMatch": {
                              "k": {
                                  "$in": [
                                      "Bob",
                                      "John",
                                      "Tim",
                                      "Ryan"
                                  ]
                              },
                              "v": {
                                  "$in": [
                                      "party_planning", "food_preparation"
                                  ]
                              }
                          }
                      }
                  }
              }
          ]
      }
      

       

       To achieve this I use the following link query:

      x => 
          x.Invitees.Organisers.Any(a => invitees.Contains(a)) 
      || (
          x.Invitees.Roles.Any(y =>
              invitees.Contains(y.Key) && roles.Any(r => y.Value.Contains(r))) && 
          !(x.Invitees.BlacklistRoles.Any(y =>
              invitees.Contains(y.Key) && roles.Any(r => y.Value.Contains(r))))
          )
      

      The full exception I receive is:

       

      System.NotSupportedException: The LINQ expression: {Invitees.Roles}.Where((Contains(value(System.Collections.Generic.List`1[System.String])) AndAlso All(value(System.Collections.Generic.HashSet`1[System.String]).Where(Contains({document}{v}))))) has the member "y" which can not be used to build a correct MongoDB query.

       

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dmitry.lukyanov Dmitry Lukyanov
              Reporter:
              tgraham@systemssoftware.com.au Taylor Graham
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: