Exemple #1
0
        protected virtual Expression VisitDeclaration(DbDeclaration decl)
        {
            ReadOnlyCollection <DbVariableDeclaration> variables = VisitVariableDeclarations(decl.Variables);
            DbSelectExpression source = (DbSelectExpression)Visit(decl.Source);

            return(UpdateDeclaration(decl, variables, source));
        }
Exemple #2
0
        protected DbDeclaration UpdateDeclaration(DbDeclaration decl,
                                                  IEnumerable <DbVariableDeclaration> variables, DbSelectExpression source)
        {
            if (variables != decl.Variables || source != decl.Source)
            {
                return(new DbDeclaration(variables, source));
            }

            return(decl);
        }
Exemple #3
0
        protected override Expression VisitDeclaration(DbDeclaration decl)
        {
            if (decl.Source != null)
            {
                // make query that returns all these declared values as an object[]
                var projection = new DbProjectionExpression(
                    decl.Source,
                    Expression.NewArrayInit(
                        typeof(object),
                        decl.Variables.Select(v => v.Expression.Type.IsValueType
                            ? Expression.Convert(v.Expression, typeof(object))
                            : v.Expression).ToArray()
                        ),
                    Aggregator.Aggregate(typeof(object[]), typeof(IEnumerable <object[]>))
                    );

                // create execution variable to hold the array of declared variables
                var vars = Expression.Parameter(typeof(object[]), "vars");
                this.variables.Add(vars);
                this.initializers.Add(Expression.Constant(null, typeof(object[])));

                // create subsitution for each variable (so it will find the variable value in the new vars array)
                for (int i = 0, n = decl.Variables.Count; i < n; i++)
                {
                    var v = decl.Variables[i];
                    DbNamedValueExpression nv = new DbNamedValueExpression(
                        v.Name, v.DbType,
                        Expression.Convert(Expression.ArrayIndex(vars, Expression.Constant(i)), v.Expression.Type)
                        );
                    this.variableMap.Add(v.Name, nv);
                }

                // make sure the execution of the select stuffs the results into the new vars array
                return(MakeAssign(vars, this.Visit(projection)));
            }

            // probably bad if we get here since we must not allow mulitple commands
            throw new InvalidOperationException("Declaration query not allowed for this langauge");
        }
 protected DbDeclaration UpdateDeclaration(DbDeclaration decl, 
     IEnumerable<DbVariableDeclaration> variables, DbSelectExpression source)
 {
     if (variables != decl.Variables || source != decl.Source)
         return new DbDeclaration(variables, source);
     
     return decl;
 }
        protected virtual Expression VisitDeclaration(DbDeclaration decl)
        {
            ReadOnlyCollection<DbVariableDeclaration> variables = VisitVariableDeclarations(decl.Variables);
            DbSelectExpression source = (DbSelectExpression)Visit(decl.Source);

            return UpdateDeclaration(decl, variables, source);
        }
 protected override Expression VisitDeclaration(DbDeclaration decl)
 {
     throw new NotSupportedException();
 }