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

InvalidOperationException when using Distinct in LINQ

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.14.0
    • Affects Version/s: 2.10.0, 2.11.2
    • Component/s: Linq
    • 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@mongodb.com James Kovacs
            Reporter:
            SSarafudinov@princeton.com Serghei Sarafudinov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: