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

ArgumentNullException when building Pull command on array element without nested property

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • 1.9.1
    • Linq
    • None

    Description

      Following code fails with ArgumentNullException:

      var participants = new[]

      { 123, 456, 789 }

      ;
      var builder = new MongoDB.Driver.Builders.UpdateBuilder<Domain.Match>();
      var mongoQuery = builder.Pull(m => m.ParticipantNumbers, query => query.Where(p => participants.Contains(p))); //This line fails with the exception

      Stack trace:
      System.ArgumentNullException: Value cannot be null.
      Parameter name: name
      at MongoDB.Driver.Builders.Query.In(String name, IEnumerable`1 values)
      at MongoDB.Driver.Linq.PredicateTranslator.BuildMethodCallQuery(MethodCallExpression methodCallExpression)
      at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
      at Test.TestClass.<>c_DisplayClass4.<TestMethod>b_3(QueryBuilder`1 query) in c:\dev\TestClass.cs:line 44
      at MongoDB.Driver.Builders.UpdateBuilder`1.Pull[TValue](Expression`1 memberExpression, Func`2 elementQueryBuilderFunction)
      . . .

      My guesses:
      It fails when calling query.Where() with lambda expression having no property access: p => participants.Contains(p). (p is a scalar value and used directly by its value). If I change the lambda to some complex object that has a property then it works: query.Where(complexObject => participants.Contains(complexObject.ParticipantNumber)). It seems that the query translator is able to translate expressions with properties only.

      Attachments

        Activity

          People

            Unassigned Unassigned
            neleus Neleus
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: