Description
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?