private InputFragment WrapJoinInputIfNecessary(InputFragment fragment, bool isRightPart)
 {
     if (fragment is SelectStatement || fragment is UnionFragment)
     {
         fragment.Wrap(scope);
         fragment.Scoped = true;
     }
     else if (fragment is JoinFragment && isRightPart)
     {
         SelectStatement select = new SelectStatement();
         select.From = fragment;
         select.Name = fragment.Name;
         select.Wrap(scope);
         return select;
     }
     return fragment;
 }
 public SelectStatement WrapIfNotCompatible(SelectStatement select, DbExpressionKind expressionKind)
 {
     if (select.IsCompatible(expressionKind)) return select;
     SelectStatement newSelect = new SelectStatement();
     select.Wrap(scope);
     select.Scoped = true;
     newSelect.From = select;
     return newSelect;
 }
        private SelectStatement VisitInputExpressionEnsureSelect(DbExpression e, string name, TypeUsage type)
        {
            InputFragment fragment = VisitInputExpression(e, name, type);
            if (fragment is SelectStatement) return (fragment as SelectStatement);

            SelectStatement s = new SelectStatement();

            // if the fragment is a union then it needs to be wrapped
            if (fragment is UnionFragment)
                (fragment as UnionFragment).Wrap(scope);

            s.From = fragment;
            return s;
        }
        public override SqlFragment Visit(DbNewInstanceExpression expression)
        {
            Debug.Assert(expression.ResultType.EdmType is CollectionType);

            SelectStatement s = new SelectStatement();

            ColumnFragment c = new ColumnFragment(null, null);
            if (expression.Arguments.Count != 0)
                c.Literal = (LiteralFragment)expression.Arguments[0].Accept(this);
            else
                c.Literal = new LiteralFragment("NULL");
            c.ColumnAlias = "X";
            s.Columns.Add(c);
            return s;
        }