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

[Regression] Linq Translation of Nested Any throws NotSupportedException

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

      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.

       

       

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

              Created:
              Updated:
              Resolved: