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

Incorrect translation of Group/Where/Select in LINQ3

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.19.0
    • Affects Version/s: 2.18.0
    • Component/s: LINQ3
    • Labels:
      None
    • Fully Compatible

      The test named `States_with_pops_over_20000_queryable_syntax` fails when run using LINQ3.

      The query is:

      var queryable =
          from z in collection.AsQueryable()
          group z by z.State into g
          where g.Sum(x => x.Population) > 20000
          select new { State = g.Key, TotalPopulation = g.Sum(x => x.Population) };
      

      The translation produced by LINQ3 is:

      Tests10151703.testcollection.Aggregate([
          { "$group" : { "_id" : "$state", "__agg0" : { "$sum" : "$pop" } } },
          { "$match" : { "$expr" : { "$gt" : [{ "$sum" : "$_elements.pop" }, 20000] } } },
          { "$project" : { "State" : "$_id", "TotalPopulation" : "$__agg0", "_id" : 0 } }
      ])
      

      but it should be:

      Tests10151703.testcollection.Aggregate([
          { "$group" : { "_id" : "$state", "__agg0" : { "$sum" : "$pop" } } },
          { "$match" : { "_agg0" : { "$gt" : 20000 } } },
          { "$project" : { "State" : "$_id", "TotalPopulation" : "$__agg0", "_id" : 0 } }
      ])
      

       
       

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

              Created:
              Updated:
              Resolved: