SelectMany doesn't support DefaultIfEmpty()

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 2.14.0
    • Affects Version/s: None
    • Component/s: LINQ, LINQ3
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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 Stam
            Reporter:
            Björn Andersson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: