// Check if the subquery is simply a stream of all of a certain entity
if (JoinTransform.isSimpleFrom(returnExpr))
{
SelectFromWhere<?> toMerge = (SelectFromWhere<?>)returnExpr;
SelectFromWhere<U> toReturn = (SelectFromWhere<U>)sfw.shallowCopy();
From from = toMerge.froms.get(0);
if (!isLeftOuterJoinCompatible(toMerge))
throw new QueryTransformException("Left outer join must be applied to a navigational link");
From.FromNavigationalLinksLeftOuterJoin outerJoinFrom = From.forNavigationalLinksLeftOuterJoin((From.FromNavigationalLinks)from);
if (isChainedLink(outerJoinFrom.links))
{
// The left outer join only applies to the end part of
// links. So we'll pull off the earlier part of the chain
// and make them a separate alias.
ReadFieldExpression outerLinks = (ReadFieldExpression)outerJoinFrom.links;
From baseFrom = From.forNavigationalLinks(outerLinks.base);
toReturn.froms.add(baseFrom);
outerJoinFrom.links = new ReadFieldExpression(new FromAliasExpression(baseFrom), outerLinks.field);
}
toReturn.froms.add(outerJoinFrom);
rewriteFromAliases(toMerge, from, outerJoinFrom);