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

Dynamic Linq expression with ParameterExpression would throw value can not be null Exception if ParameterName not set

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.14.0
    • Affects Version/s: None
    • Component/s: Linq
    • None

      Dynamically create a Expression, Define the parameter of the Expression as below

      var parameter = Expression.Parameter(typeof(T));

      then pass this expression to MongoQueryable.Where function

      call Count or ToList

      reported the below exception

      Value cannot be null.
      Parameter name: itemName

       

      on the other hand, if i declare the parameter of the expression as below

      var parameter = Expression.Parameter(typeof(T),"item");

      then the linq expression can be successfully transformed to mongodb query

       

      while transform the linq expression to mongodb query, why does the parameter name is required? when it comes to dynamically generated expression people usually use anonymous parameter and the exception message does not explicitly indicate the parameter expression need a name. 

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            elendil elendil
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: