public void ShouldTranslateInsertExpression() { var dbInsertQuery = new DbInsertQuery(); var expression = dbInsertQuery.Insert(e => e.Table("SomeTable")) .Columns(e => e.Column("SomeColumn")).Values(e => e.Constant(1)); var result = QueryTranslator.Translate(expression); Assert.AreEqual(InsertExpressionSyntax.Clean(), result.Sql.Clean()); }
/// <summary> /// Specifies the target columns. /// </summary> /// <param name="dbInsertQuery">The target <see cref="DbQuery{TQueryExpression}"/>.</param> /// <param name="columnsExpression">The <see cref="DbExpression"/> that represents the target columns.</param> /// <returns>A <see cref="DbInsertQuery"/> instance.</returns> public static DbInsertQuery Columns(this DbInsertQuery dbInsertQuery, DbExpression columnsExpression) { dbInsertQuery.QueryExpression.TargetColumns = columnsExpression; return(dbInsertQuery); }
/// <summary> /// Creates a <see cref="DbQuery{TQueryExpression}"/> that is used to insert data into the database. /// </summary> /// <param name="dbInsertQuery">The target <see cref="DbInsertQuery"/>.</param> /// <param name="target">The <see cref="DbExpression"/> that represents the target table or view.</param> /// <returns>A <see cref="DbInsertQuery"/> instance.</returns> public static DbInsertQuery Insert(this DbInsertQuery dbInsertQuery, DbExpression target) { dbInsertQuery.QueryExpression.Target = target; return(dbInsertQuery); }
/// <summary> /// Specifies the target columns. /// </summary> /// <param name="dbInsertQuery">The target <see cref="DbQuery{TQueryExpression}"/>.</param> /// <param name="columnSelector">A function used to specify the target columns.</param> /// <returns>A <see cref="DbInsertQuery"/> instance.</returns> public static DbInsertQuery Columns(this DbInsertQuery dbInsertQuery, params Func <DbExpressionFactory, DbExpression>[] columnSelector) { return(Columns(dbInsertQuery, DbExpressionFactory.List(columnSelector.Select(e => e(DbExpressionFactory))))); }
/// <summary> /// Creates a <see cref="DbQuery{TQueryExpression}"/> that is used to insert data into the database. /// </summary> /// <param name="dbInsertQuery">The target <see cref="DbInsertQuery"/>.</param> /// <param name="targetSelector">A <see cref="Func{T,TResult}"/> used to /// specify the <see cref="DbExpression"/> that represents the target table or view.</param> /// <returns>A <see cref="DbInsertQuery"/> instance.</returns> public static DbInsertQuery Insert(this DbInsertQuery dbInsertQuery, Func <DbExpressionFactory, DbExpression> targetSelector) { return(Insert(dbInsertQuery, targetSelector(DbExpressionFactory))); }