Esempio n. 1
0
        public override ExecutableQueryExpression BuildQuery()
        {
            var where = _whereBuilder.Build();

            if (where?.RequiresJoins == true)
            {
                throw new InvalidOperationException("Expressions that require joins aren't valid for DELETE statements.");
            }

            return(QueryExpression.Delete(
                       QueryExpression.Table(_tableName), where?.QueryExpression
                       ));
        }
Esempio n. 2
0
        public override ExecutableQueryExpression BuildQuery()
        {
            var where = _whereBuilder.Build();
            var assignments = _assignments.Build();

            if (where?.RequiresJoins == true)
            {
                throw new InvalidOperationException("Expressions that require joins aren't valid for DELETE statements.");
            }

            return(QueryExpression.Update(
                       QueryExpression.Table(_tableName),
                       where : where?.QueryExpression,
                       columns: assignments.Columns,
                       values: assignments.Row
                       ));
        }
Esempio n. 3
0
        public override ExecutableQueryExpression BuildQuery()
        {
            var projectionExpressions = _projectionBuilder.ProjectionExpressions.ToArray();

            if (projectionExpressions.Length < 1)
            {
                throw new InvalidOperationException("At least 1 projected field must be specified.");
            }

            var where = _whereBuilder.Build();
            var having  = _havingBuilder.Build();
            var limit   = _rangeBuilder.Build();
            var groupBy = _groupByBuilder.Build();
            var orderBy = _orderByBuilder.Build();

            var groupByExpressions = groupBy?.Select(q => q.QueryExpression).OfType <GroupByQueryExpression>().ToArray();
            var groupByJoins       = groupBy?.Where(q => q.RequiresJoins).SelectMany(q => q.Joins).ToArray();

            var orderByExpressions = orderBy?.Select(q => q.QueryExpression).OfType <OrderByQueryExpression>().ToArray();
            var orderByJoins       = orderBy?.Where(q => q.RequiresJoins).SelectMany(q => q.Joins).ToArray();

            var joins = ConcatUniqueJoins(
                _projectionBuilder.Joins.ToArray(),
                where?.Joins,
                having?.Joins,
                limit?.Joins,
                groupByJoins,
                orderByJoins
                );
            var builtJoins = joins.Select(q => q.Build()).ToArray();

            return(QueryExpression.Select(
                       projection: projectionExpressions,
                       from: QueryExpression.Table(_tableName),
                       joins: builtJoins,
                       where : where?.QueryExpression,
                       having: having?.QueryExpression,
                       limit: limit?.QueryExpression as LimitQueryExpression,
                       orderBy: orderByExpressions,
                       groupBy: groupByExpressions
                       ));
        }