RelationalDatabaseFacadeExtensions.ExecuteSqlCommandAsync 方法

定義

多載

ExecuteSqlCommandAsync(DatabaseFacade, String, CancellationToken, Object[])
ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, IEnumerable<Object>, CancellationToken)
已淘汰.

針對資料庫執行指定的 SQL,並傳回受影響的資料列數目。

請注意,這個方法不會啟動交易。 若要搭配交易使用這個方法,請先呼叫 BeginTransaction(DatabaseFacade, IsolationLevel)UseTransaction(DatabaseFacade, DbTransaction)

請注意,這個方法不會使用目前的 ExecutionStrategy ,因為 SQL 可能不是等冪,也不會在交易中執行。 您可以明確使用 ExecutionStrategy,如果 SQL 不具等冪性,請務必也使用交易。

如同任何接受 SQL 的 API,請務必將任何使用者輸入參數化,以防止 SQL 插入式攻擊。 您可以在 SQL 查詢字串中包含參數預留位置,然後提供參數值作為其他引數。 您提供的任何參數值都會自動轉換成 DbParameter。 您也可以考慮使用 ExecuteSqlInterpolated 來使用插補字串語法來建立參數。

ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, CancellationToken)
已淘汰.

針對資料庫執行指定的 SQL,並傳回受影響的資料列數目。

請注意,這個方法不會啟動交易。 若要搭配交易使用這個方法,請先呼叫 BeginTransaction(DatabaseFacade, IsolationLevel)UseTransaction(DatabaseFacade, DbTransaction)

請注意,這個方法不會使用目前的 ExecutionStrategy ,因為 SQL 可能不是等冪,也不會在交易中執行。 您可以明確使用 ExecutionStrategy,如果 SQL 不具等冪性,請務必也使用交易。

如同任何接受 SQL 的 API,請務必將任何使用者輸入參數化,以防止 SQL 插入式攻擊。 您可以在 SQL 查詢字串中包含參數預留位置,然後提供參數值作為其他引數。 您提供的任何參數值都會自動轉換成 DbParameter - context.Database.ExecuteSqlCommandAsync("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)

ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, Object[])
已淘汰.

針對資料庫執行指定的 SQL,並傳回受影響的資料列數目。

請注意,這個方法不會啟動交易。 若要搭配交易使用這個方法,請先呼叫 BeginTransaction(DatabaseFacade, IsolationLevel)UseTransaction(DatabaseFacade, DbTransaction)

請注意,這個方法不會使用目前的 ExecutionStrategy ,因為 SQL 可能不是等冪,也不會在交易中執行。 您可以明確使用 ExecutionStrategy,如果 SQL 不具等冪性,請務必也使用交易。

如同任何接受 SQL 的 API,請務必將任何使用者輸入參數化,以防止 SQL 插入式攻擊。 您可以在 SQL 查詢字串中包含參數預留位置,然後提供參數值作為其他引數。 您提供的任何參數值都會自動轉換成 DbParameter - context.Database.ExecuteSqlCommandAsync("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm) 。 您也可以考慮使用 ExecuteSqlInterpolated 來使用插補字串語法來建立參數。

ExecuteSqlCommandAsync(DatabaseFacade, FormattableString, CancellationToken)
已淘汰.

針對資料庫執行指定的 SQL,並傳回受影響的資料列數目。

請注意,這個方法不會啟動交易。 若要搭配交易使用這個方法,請先呼叫 BeginTransaction(DatabaseFacade, IsolationLevel)UseTransaction(DatabaseFacade, DbTransaction)

請注意,這個方法不會使用目前的 ExecutionStrategy ,因為 SQL 可能不是等冪,也不會在交易中執行。 您可以明確使用 ExecutionStrategy,如果 SQL 不具等冪性,請務必也使用交易。

如同任何接受 SQL 的 API,請務必將任何使用者輸入參數化,以防止 SQL 插入式攻擊。 您可以在 SQL 查詢字串中包含參數預留位置,然後提供參數值作為其他引數。 您提供的任何參數值都會自動轉換成 DbParameter - context.Database.ExecuteSqlCommandAsync($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")

ExecuteSqlCommandAsync(DatabaseFacade, String, CancellationToken, Object[])

public static System.Threading.Tasks.Task<int> ExecuteSqlCommandAsync (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, string sql, System.Threading.CancellationToken cancellationToken = default, params object[] parameters);
static member ExecuteSqlCommandAsync : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * string * System.Threading.CancellationToken * obj[] -> System.Threading.Tasks.Task<int>
<Extension()>
Public Function ExecuteSqlCommandAsync (databaseFacade As DatabaseFacade, sql As String, Optional cancellationToken As CancellationToken = Nothing, ParamArray parameters As Object()) As Task(Of Integer)

參數

databaseFacade
DatabaseFacade
sql
String
cancellationToken
CancellationToken
parameters
Object[]

傳回

適用於

ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, IEnumerable<Object>, CancellationToken)

警告

For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.

針對資料庫執行指定的 SQL,並傳回受影響的資料列數目。

請注意,這個方法不會啟動交易。 若要搭配交易使用這個方法,請先呼叫 BeginTransaction(DatabaseFacade, IsolationLevel)UseTransaction(DatabaseFacade, DbTransaction)

請注意,這個方法不會使用目前的 ExecutionStrategy ,因為 SQL 可能不是等冪,也不會在交易中執行。 您可以明確使用 ExecutionStrategy,如果 SQL 不具等冪性,請務必也使用交易。

如同任何接受 SQL 的 API,請務必將任何使用者輸入參數化,以防止 SQL 插入式攻擊。 您可以在 SQL 查詢字串中包含參數預留位置,然後提供參數值作為其他引數。 您提供的任何參數值都會自動轉換成 DbParameter。 您也可以考慮使用 ExecuteSqlInterpolated 來使用插補字串語法來建立參數。

public static System.Threading.Tasks.Task<int> ExecuteSqlCommandAsync (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, Microsoft.EntityFrameworkCore.RawSqlString sql, System.Collections.Generic.IEnumerable<object> parameters, System.Threading.CancellationToken cancellationToken = default);
[System.Obsolete("For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.")]
public static System.Threading.Tasks.Task<int> ExecuteSqlCommandAsync (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, Microsoft.EntityFrameworkCore.RawSqlString sql, System.Collections.Generic.IEnumerable<object> parameters, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteSqlCommandAsync : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * Microsoft.EntityFrameworkCore.RawSqlString * seq<obj> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
[<System.Obsolete("For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.")>]
static member ExecuteSqlCommandAsync : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * Microsoft.EntityFrameworkCore.RawSqlString * seq<obj> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
<Extension()>
Public Function ExecuteSqlCommandAsync (databaseFacade As DatabaseFacade, sql As RawSqlString, parameters As IEnumerable(Of Object), Optional cancellationToken As CancellationToken = Nothing) As Task(Of Integer)

參數

databaseFacade
DatabaseFacade

DatabaseFacade內容的 。

sql
RawSqlString

要執行的 SQL。

parameters
IEnumerable<Object>

要與 SQL 搭配使用的參數。

cancellationToken
CancellationToken

CancellationToken等候工作完成時要觀察的 。

傳回

代表非同步作業的工作。 工作結果是受影響的資料列數目。

屬性

適用於

ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, CancellationToken)

警告

For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.

針對資料庫執行指定的 SQL,並傳回受影響的資料列數目。

請注意,這個方法不會啟動交易。 若要搭配交易使用這個方法,請先呼叫 BeginTransaction(DatabaseFacade, IsolationLevel)UseTransaction(DatabaseFacade, DbTransaction)

請注意,這個方法不會使用目前的 ExecutionStrategy ,因為 SQL 可能不是等冪,也不會在交易中執行。 您可以明確使用 ExecutionStrategy,如果 SQL 不具等冪性,請務必也使用交易。

如同任何接受 SQL 的 API,請務必將任何使用者輸入參數化,以防止 SQL 插入式攻擊。 您可以在 SQL 查詢字串中包含參數預留位置,然後提供參數值作為其他引數。 您提供的任何參數值都會自動轉換成 DbParameter - context.Database.ExecuteSqlCommandAsync("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)

public static System.Threading.Tasks.Task<int> ExecuteSqlCommandAsync (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, Microsoft.EntityFrameworkCore.RawSqlString sql, System.Threading.CancellationToken cancellationToken = default);
[System.Obsolete("For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.")]
public static System.Threading.Tasks.Task<int> ExecuteSqlCommandAsync (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, Microsoft.EntityFrameworkCore.RawSqlString sql, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteSqlCommandAsync : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * Microsoft.EntityFrameworkCore.RawSqlString * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
[<System.Obsolete("For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.")>]
static member ExecuteSqlCommandAsync : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * Microsoft.EntityFrameworkCore.RawSqlString * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
<Extension()>
Public Function ExecuteSqlCommandAsync (databaseFacade As DatabaseFacade, sql As RawSqlString, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Integer)

參數

databaseFacade
DatabaseFacade

DatabaseFacade內容的 。

sql
RawSqlString

要執行的 SQL。

cancellationToken
CancellationToken

CancellationToken等候工作完成時要觀察的 。

傳回

代表非同步作業的工作。 工作結果是受影響的資料列數目。

屬性

適用於

ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, Object[])

警告

For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.

針對資料庫執行指定的 SQL,並傳回受影響的資料列數目。

請注意,這個方法不會啟動交易。 若要搭配交易使用這個方法,請先呼叫 BeginTransaction(DatabaseFacade, IsolationLevel)UseTransaction(DatabaseFacade, DbTransaction)

請注意,此方法不會使用目前的 ExecutionStrategy ,因為 SQL 可能不是等冪,而且不會在交易中執行。 可以明確使用 ExecutionStrategy,如果 SQL 不是等冪性,請務必也使用交易。

如同接受 SQL 的任何 API,請務必將任何使用者輸入參數化,以防止 SQL 插入式攻擊。 您可以在 SQL 查詢字串中包含參數預留位置,然後提供參數值作為其他引數。 您提供的任何參數值都會自動轉換成 DbParameter - context.Database.ExecuteSqlCommandAsync("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm) 。 您也可以考慮使用 ExecuteSqlInterpolated 來使用插補字串語法來建立參數。

public static System.Threading.Tasks.Task<int> ExecuteSqlCommandAsync (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, Microsoft.EntityFrameworkCore.RawSqlString sql, params object[] parameters);
[System.Obsolete("For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.")]
public static System.Threading.Tasks.Task<int> ExecuteSqlCommandAsync (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, Microsoft.EntityFrameworkCore.RawSqlString sql, params object[] parameters);
static member ExecuteSqlCommandAsync : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * Microsoft.EntityFrameworkCore.RawSqlString * obj[] -> System.Threading.Tasks.Task<int>
[<System.Obsolete("For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.")>]
static member ExecuteSqlCommandAsync : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * Microsoft.EntityFrameworkCore.RawSqlString * obj[] -> System.Threading.Tasks.Task<int>
<Extension()>
Public Function ExecuteSqlCommandAsync (databaseFacade As DatabaseFacade, sql As RawSqlString, ParamArray parameters As Object()) As Task(Of Integer)

參數

databaseFacade
DatabaseFacade

DatabaseFacade內容的 。

sql
RawSqlString

要執行的 SQL。

parameters
Object[]

要搭配 SQL 使用的參數。

傳回

代表非同步作業的工作。 工作結果是受影響的資料列數目。

屬性

適用於

ExecuteSqlCommandAsync(DatabaseFacade, FormattableString, CancellationToken)

警告

For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.

針對資料庫執行指定的 SQL,並傳回受影響的資料列數目。

請注意,這個方法不會啟動交易。 若要搭配交易使用這個方法,請先呼叫 BeginTransaction(DatabaseFacade, IsolationLevel)UseTransaction(DatabaseFacade, DbTransaction)

請注意,此方法不會使用目前的 ExecutionStrategy ,因為 SQL 可能不是等冪,而且不會在交易中執行。 可以明確使用 ExecutionStrategy,如果 SQL 不是等冪性,請務必也使用交易。

如同接受 SQL 的任何 API,請務必將任何使用者輸入參數化,以防止 SQL 插入式攻擊。 您可以在 SQL 查詢字串中包含參數預留位置,然後提供參數值作為其他引數。 您提供的任何參數值都會自動轉換成 DbParameter - context.Database.ExecuteSqlCommandAsync($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")

public static System.Threading.Tasks.Task<int> ExecuteSqlCommandAsync (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, FormattableString sql, System.Threading.CancellationToken cancellationToken = default);
[System.Obsolete("For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.")]
public static System.Threading.Tasks.Task<int> ExecuteSqlCommandAsync (this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, FormattableString sql, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteSqlCommandAsync : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * FormattableString * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
[<System.Obsolete("For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.")>]
static member ExecuteSqlCommandAsync : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * FormattableString * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
<Extension()>
Public Function ExecuteSqlCommandAsync (databaseFacade As DatabaseFacade, sql As FormattableString, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Integer)

參數

databaseFacade
DatabaseFacade

DatabaseFacade內容的 。

sql
FormattableString

內插字串,表示具有參數的 SQL 查詢。

cancellationToken
CancellationToken

等候 CancellationToken 工作完成時要觀察的 。

傳回

代表非同步作業的工作。 工作結果是受影響的資料列數目。

屬性

適用於