Exemplo n.º 1
0
        static void BuildTake(ExpressionBuilder builder, IBuildContext sequence, ISqlExpression expr)
        {
            var sql = sequence.SelectQuery;

            sql.Select.Take(expr);

            if (sql.Select.SkipValue != null &&
                builder.DataContextInfo.SqlProviderFlags.IsTakeSupported &&
                !builder.DataContextInfo.SqlProviderFlags.GetIsSkipSupportedFlag(sql))
            {
                if (sql.Select.SkipValue is SqlParameter && sql.Select.TakeValue is SqlValue)
                {
                    var skip = (SqlParameter)sql.Select.SkipValue;
                    var parm = (SqlParameter)sql.Select.SkipValue.Clone(new Dictionary <ICloneableElement, ICloneableElement>(), _ => true);

                    parm.SetTakeConverter((int)((SqlValue)sql.Select.TakeValue).Value);

                    sql.Select.Take(parm);

                    var ep = (from pm in builder.CurrentSqlParameters where pm.SqlParameter == skip select pm).First();

                    ep = new ParameterAccessor
                    {
                        Expression   = ep.Expression,
                        Accessor     = ep.Accessor,
                        SqlParameter = parm
                    };

                    builder.CurrentSqlParameters.Add(ep);
                }
                else
                {
                    sql.Select.Take(builder.Convert(
                                        sequence,
                                        new SqlBinaryExpression(typeof(int), sql.Select.SkipValue, "+", sql.Select.TakeValue, Precedence.Additive)));
                }
            }

            if (!builder.DataContextInfo.SqlProviderFlags.GetAcceptsTakeAsParameterFlag(sql))
            {
                var p = sql.Select.TakeValue as SqlParameter;

                if (p != null)
                {
                    p.IsQueryParameter = false;
                }
            }
        }
Exemplo n.º 2
0
        static void BuildSubQueryJoin(
            ExpressionBuilder builder,
            IBuildContext outerKeyContext, Expression outerKeySelector,
            Expression innerKeySelector,
            IBuildContext subQueryKeyContext, SelectQuery subQuerySelect)
        {
            var predicate = builder.ConvertObjectComparison(
                ExpressionType.Equal,
                outerKeyContext, outerKeySelector,
                subQueryKeyContext, innerKeySelector);

            if (predicate == null)
            {
                predicate = new SelectQuery.Predicate.ExprExpr(
                    builder.ConvertToSql(outerKeyContext, outerKeySelector),
                    SelectQuery.Predicate.Operator.Equal,
                    builder.ConvertToSql(subQueryKeyContext, innerKeySelector));

                predicate = builder.Convert(outerKeyContext, predicate);
            }

            subQuerySelect.Where.SearchCondition.Conditions.Add(new SelectQuery.Condition(false, predicate));
        }
Exemplo n.º 3
0
        static void BuildJoin(
            ExpressionBuilder builder,
            SelectQuery.FromClause.Join join,
            IBuildContext outerKeyContext, Expression outerKeySelector,
            IBuildContext innerKeyContext, Expression innerKeySelector)
        {
            var predicate = builder.ConvertObjectComparison(
                ExpressionType.Equal,
                outerKeyContext, outerKeySelector,
                innerKeyContext, innerKeySelector);

            if (predicate == null)
            {
                predicate = new SelectQuery.Predicate.ExprExpr(
                    builder.ConvertToSql(outerKeyContext, outerKeySelector),
                    SelectQuery.Predicate.Operator.Equal,
                    builder.ConvertToSql(innerKeyContext, innerKeySelector));

                predicate = builder.Convert(outerKeyContext, predicate);
            }

            join.JoinedTable.Condition.Conditions.Add(new SelectQuery.Condition(false, predicate));
        }