Exemplo n.º 1
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.º 2
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));
        }
Exemplo n.º 3
0
        internal static void ParseSet(
            ExpressionBuilder builder,
            BuildInfo buildInfo,
            LambdaExpression extract,
            Expression update,
            IBuildContext select,
            List <SelectQuery.SetExpression> items)
        {
            var ext = extract.Body;

            if (!update.Type.IsConstantable() && !builder.AsParameters.Contains(update))
            {
                builder.AsParameters.Add(update);
            }

            while (ext.NodeType == ExpressionType.Convert || ext.NodeType == ExpressionType.ConvertChecked)
            {
                ext = ((UnaryExpression)ext).Operand;
            }

            if (ext.NodeType != ExpressionType.MemberAccess || ext.GetRootObject() != extract.Parameters[0])
            {
                throw new LinqException("Member expression expected for the 'Set' statement.");
            }

            var body   = (MemberExpression)ext;
            var member = body.Member;

            if (member is MethodInfo)
            {
                member = ((MethodInfo)member).GetPropertyInfo();
            }

            var column = select.ConvertToSql(body, 1, ConvertFlags.Field);

            if (column.Length == 0)
            {
                throw new LinqException("Member '{0}.{1}' is not a table column.", member.DeclaringType.Name, member.Name);
            }

            var expr = builder.ConvertToSql(select, update);

            items.Add(new SelectQuery.SetExpression(column[0].Sql, expr));
        }
Exemplo n.º 4
0
        protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
        {
            var sequence = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]));

            var arg = methodCall.Arguments[1].Unwrap();

            if (arg.NodeType == ExpressionType.Lambda)
            {
                arg = ((LambdaExpression)arg).Body.Unwrap();
            }

            var expr = builder.ConvertToSql(sequence, arg);

            if (methodCall.Method.Name == "Take")
            {
                BuildTake(builder, sequence, expr);
            }
            else
            {
                BuildSkip(builder, sequence, sequence.SelectQuery.Select.SkipValue, expr);
            }

            return(sequence);
        }