public RelationalCommand GenerateSql(IDictionary<string, object> parameterValues)
        {
            DbInsertCommandTree commandTree = tree as DbInsertCommandTree;

            InsertStatement statement = new InsertStatement();

            DbExpressionBinding e = commandTree.Target;
            statement.Target = (InputFragment)e.Expression.Accept(this);

            foreach (DbSetClause setClause in commandTree.SetClauses)
                statement.Sets.Add(setClause.Property.Accept(this));

            foreach (DbSetClause setClause in commandTree.SetClauses)
            {
                DbExpression value = setClause.Value;
                SqlFragment valueFragment = value.Accept(this);
                statement.Values.Add(valueFragment);

                if (values == null)
                    values = new Dictionary<EdmMember, SqlFragment>();

                if (value.ExpressionKind != DbExpressionKind.Null)
                {
                    EdmMember property = ((DbPropertyExpression)setClause.Property).Property;
                    values.Add(property, valueFragment);
                }
            }

            if (commandTree.Returning != null)
                statement.ReturningSelect = GenerateReturningSql(commandTree, commandTree.Returning);

            return statement.ToString();
        }
示例#2
0
        public override string GenerateSQL(DbCommandTree tree)
        {
            DbInsertCommandTree commandTree = tree as DbInsertCommandTree;

            InsertStatement statement = new InsertStatement();

            DbExpressionBinding e = commandTree.Target;

            statement.Target = (InputFragment)e.Expression.Accept(this);

            foreach (DbSetClause setClause in commandTree.SetClauses)
            {
                statement.Sets.Add(setClause.Property.Accept(this));
            }

            foreach (DbSetClause setClause in commandTree.SetClauses)
            {
                DbExpression value         = setClause.Value;
                SqlFragment  valueFragment = value.Accept(this);
                statement.Values.Add(valueFragment);

                if (values == null)
                {
                    values = new Dictionary <EdmMember, SqlFragment>();
                }

                if (value.ExpressionKind != DbExpressionKind.Null)
                {
                    EdmMember property = ((DbPropertyExpression)setClause.Property).Property;
                    values.Add(property, valueFragment);
                }
            }

            if (commandTree.Returning != null)
            {
                statement.ReturningSelect = GenerateReturningSql(commandTree, commandTree.Returning);
            }

            return(statement.ToString());
        }