Inheritance: SqlFragment
    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);

      scope.Add("target", statement.Target);

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

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

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

        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();
    }
Exemple #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);

            scope.Add("target", statement.Target);

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

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

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

                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());
        }