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

SelectMany doesn't support DefaultIfEmpty()

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

      When unwinding lists using SelectMany, there is no way to force preserveNullAndEmptyArrays in the generated query.

      By adding DefaultIfEmpty() to the SelectMany as follows

       

       

      query.SelectMany(outerObject => outerObject.InnerArray.DefaultIfEmpty(), (o, a)...

       

       

      it would be expected that an unwind with the preserveNullAndEmptyArrays option would be generated and empty lists that are unwinded would generate a copy of the parent object with a default object of the child.

      By simply changing MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateSelectMany line 340 from

       

       

      var groupJoin = node.Source as GroupJoinExpression;
      if (groupJoin != null && isLeftOuterJoin) 
      

       

      to (i.e. remove the restriction to be a group join)

       

      if (isLeftOuterJoin)

       

      The desired result is achieved. However, this may cause unintended side-effects because I cannot understand why this support is not already there?

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            bjorn@livewrapped.com Björn Andersson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: