InvalidOperationException when using Distinct in LINQ

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 2.14.0
    • Affects Version/s: 2.10.0, 2.11.2
    • Component/s: LINQ
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I have a code like this in my ASP.NET Core app

      var evtQry = from pe in EventDocCollection.AsQueryable()
                          where pe.Create.User.Id == user.Id
                          orderby pe.DateTime descending
                          select pe.Id;
      var eventIds = await evtQry.Distinct().Take(20).ToListAsync();
      

      and it throws the following exception when executed:

      System.InvalidOperationException: Extension node must override the property Expression.Type.
         at System.Linq.Expressions.Expression.get_Type()
         at MongoDB.Driver.Linq.Expressions.GroupByExpression..ctor(Expression source, Expression keySelector)
         at MongoDB.Driver.Linq.Processors.Pipeline.MethodCallBinders.DistinctBinder.Bind(PipelineExpression pipeline, PipelineBindingContext bindingContext, MethodCallExpression node, IEnumerable`1 arguments)
         at MongoDB.Driver.Linq.Processors.MethodInfoMethodCallBinder`1.Bind(PipelineExpression pipeline, TBindingContext bindingContext, MethodCallExpression node, IEnumerable`1 arguments)
         at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.BindMethodCall(MethodCallExpression node)
      

      Do you have any idea why this exception is thrown? It looks like a problem with the C# driver. 

            Assignee:
            James Kovacs
            Reporter:
            Serghei Sarafudinov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: