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

IQueryable breaks if query is prefixed with SELECT statement

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

      I'm trying to connect some framework that is based on IQueryable interface (i.e. OData if you wonder).

      My current problem can be described using following snippet:

      var queryable = database.GetCollection<MyItems>("myItems").AsQueryable();
      var count1 = queryable.Select(x => x.Order.StateInfo).Count();
      // var count2 = queryable.Select(x => x.Order).Select(x => x.StateInfo).Count();

      This code works but if you uncomment the last line you get:

       

      System.ArgumentException: Expression of type 'System.Collections.Generic.IEnumerable`1[MyApp.Common.Models.StateInfo]' 
      cannot be used for parameter of type 'System.Linq.IQueryable`1[MyApp.Common.Models.StateInfo]' of method
       'Int32 Count[StateInfo](System.Linq.IQueryable`1[MyApp.Common.Models.StateInfo])' (Parameter 'arg0')
       at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
       at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0)
       at System.Linq.Expressions.MethodCallExpression1.Rewrite(Expression instance, IReadOnlyList`1 args)
       at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
       at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
       at MongoDB.Driver.Linq.Processors.Transformer.Visit(Expression node)
       at MongoDB.Driver.Linq.Processors.Transformer.Transform(Expression node)
       at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Prepare(Expression expression)
       at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Translate(Expression expression)
       at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
       at MongoDB.Driver.Linq.MongoQueryable.CountAsync[TSource](IMongoQueryable`1 source, CancellationToken cancellationToken)

      It seems that driver tries to perform some operations in-memory, dropping the whole `IQueryable` thing, so all the subsequent calls fail (like Select/Where/...). Query with two subsequent `Select`'s or `Select/Where` pair get efficiently poisoned and cannot be used anywhere. For example:

       

      var queryable = database.GetCollection<MyItems>("myItems").AsQueryable();
      var count1 = queryable.Select(x => x.Order).Where(x => x.StateInfo != null).Count(); 
      // System.InvalidOperationException: '{document}.StateInfo is not supported.'

            Assignee:
            Unassigned Unassigned
            Reporter:
            pzixel@gmail.com Alex Zhuk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: