RelationalDatabaseFacadeExtensions.ExecuteSqlInterpolated 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
警告
Use ExecuteSql() instead. This method is obsolete and will be removed in a future release.
對資料庫執行給定的 SQL,並回傳受影響的列數。
public static int ExecuteSqlInterpolated(this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, FormattableString sql);
[System.Obsolete("Use ExecuteSql() instead. This method is obsolete and will be removed in a future release.")]
public static int ExecuteSqlInterpolated(this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade databaseFacade, FormattableString sql);
static member ExecuteSqlInterpolated : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * FormattableString -> int
[<System.Obsolete("Use ExecuteSql() instead. This method is obsolete and will be removed in a future release.")>]
static member ExecuteSqlInterpolated : Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade * FormattableString -> int
<Extension()>
Public Function ExecuteSqlInterpolated (databaseFacade As DatabaseFacade, sql As FormattableString) As Integer
參數
- databaseFacade
- DatabaseFacade
這是 DatabaseFacade 給你背景的。
插值字串代表帶有參數的 SQL 查詢。
傳回
受影響的行數。
- 屬性
備註
請注意,此方法不會啟動交易。 若要使用此方法處理交易,首先呼叫 BeginTransaction(DatabaseFacade, IsolationLevel) 或 UseTransaction。
請注意,此方法不使用當前 ExecutionStrategy 值,因為 SQL 可能不是冪등元,且不在交易中執行。 An ExecutionStrategy 可以明確使用,若 SQL 非冪등 式,請確保同時使用交易。
和任何接受 SQL 的 API 一樣,必須對使用者輸入進行參數化,以防止 SQL 注入攻擊。 你可以在 SQL 查詢字串中加入參數佔位符,然後以參數值作為額外參數。 你提供的任何參數值都會自動轉換成 DbParameter。
更多資訊與範例請參閱「 使用 EF Core 執行原始 SQL 指令 」。