Database::ExecuteSqlCommandAsync Method

Entity Framework 6.0
 

Asynchronously executes the given DDL/DML command against the database.

Namespace:   System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

NameDescription
System_CAPS_pubmethodExecuteSqlCommandAsync(String^, CancellationToken, array<Object^>^)

Asynchronously executes the given DDL/DML command against the database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

System_CAPS_pubmethodExecuteSqlCommandAsync(String^, array<Object^>^)

Asynchronously executes the given DDL/DML command against the database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

System_CAPS_pubmethodExecuteSqlCommandAsync(TransactionalBehavior, String^, CancellationToken, array<Object^>^)

Asynchronously executes the given DDL/DML command against the database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

System_CAPS_pubmethodExecuteSqlCommandAsync(TransactionalBehavior, String^, array<Object^>^)

Asynchronously executes the given DDL/DML command against the database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

Return to top

Database::ExecuteSqlCommandAsync Method (String^, CancellationToken, array<Object^>^)

Asynchronously executes the given DDL/DML command against the database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

public:
Task<int>^ ExecuteSqlCommandAsync(
	String^ sql,
	CancellationToken cancellationToken,
	... array<Object^>^ parameters
)

Parameters

sql
Type: System::String^

The command string.

cancellationToken
Type: System.Threading::CancellationToken

A CancellationToken to observe while waiting for the task to complete.

parameters
Type: array<System::Object^>^

The parameters to apply to the command string.

Return Value

Type: System.Threading.Tasks::Task<Int32>^

A task that represents the asynchronous operation. The task result contains the result returned by the database after executing the command.

Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. If there isn't an existing local transaction a new transaction will be used to execute the command.

Return to top

Database::ExecuteSqlCommandAsync Method (String^, array<Object^>^)

Asynchronously executes the given DDL/DML command against the database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

public:
Task<int>^ ExecuteSqlCommandAsync(
	String^ sql,
	... array<Object^>^ parameters
)

Parameters

sql
Type: System::String^

The command string.

parameters
Type: array<System::Object^>^

The parameters to apply to the command string.

Return Value

Type: System.Threading.Tasks::Task<Int32>^

A task that represents the asynchronous operation. The task result contains the result returned by the database after executing the command.

Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. If there isn't an existing local transaction a new transaction will be used to execute the command.

Return to top

Database::ExecuteSqlCommandAsync Method (TransactionalBehavior, String^, CancellationToken, array<Object^>^)

Asynchronously executes the given DDL/DML command against the database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

public:
Task<int>^ ExecuteSqlCommandAsync(
	TransactionalBehavior transactionalBehavior,
	String^ sql,
	CancellationToken cancellationToken,
	... array<Object^>^ parameters
)

Parameters

transactionalBehavior
Type: System.Data.Entity::TransactionalBehavior

Controls the creation of a transaction for this command.

sql
Type: System::String^

The command string.

cancellationToken
Type: System.Threading::CancellationToken

A CancellationToken to observe while waiting for the task to complete.

parameters
Type: array<System::Object^>^

The parameters to apply to the command string.

Return Value

Type: System.Threading.Tasks::Task<Int32>^

A task that represents the asynchronous operation. The task result contains the result returned by the database after executing the command.

Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.

Return to top

Database::ExecuteSqlCommandAsync Method (TransactionalBehavior, String^, array<Object^>^)

Asynchronously executes the given DDL/DML command against the database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.Database.ExecuteSqlCommandAsync("UPDATE dbo.Posts SET Rating = 5 WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

public:
Task<int>^ ExecuteSqlCommandAsync(
	TransactionalBehavior transactionalBehavior,
	String^ sql,
	... array<Object^>^ parameters
)

Parameters

transactionalBehavior
Type: System.Data.Entity::TransactionalBehavior

Controls the creation of a transaction for this command.

sql
Type: System::String^

The command string.

parameters
Type: array<System::Object^>^

The parameters to apply to the command string.

Return Value

Type: System.Threading.Tasks::Task<Int32>^

A task that represents the asynchronous operation. The task result contains the result returned by the database after executing the command.

Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.

Return to top
Show: