語言

RelationalQueryableExtensions.FromSqlInterpolated<TEntity> 方法

定義

警告

Use FromSql() instead. This method is obsolete and will be removed in a future release.

根據一個插值字串(代表 SQL 查詢)建立一個 LINQ 查詢。

public static System.Linq.IQueryable<TEntity> FromSqlInterpolated<TEntity>(this Microsoft.EntityFrameworkCore.DbSet<TEntity> source, FormattableString sql) where TEntity : class;
[System.Obsolete("Use FromSql() instead. This method is obsolete and will be removed in a future release.")]
public static System.Linq.IQueryable<TEntity> FromSqlInterpolated<TEntity>(this Microsoft.EntityFrameworkCore.DbSet<TEntity> source, FormattableString sql) where TEntity : class;
static member FromSqlInterpolated : Microsoft.EntityFrameworkCore.DbSet<'Entity (requires 'Entity : null)> * FormattableString -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
[<System.Obsolete("Use FromSql() instead. This method is obsolete and will be removed in a future release.")>]
static member FromSqlInterpolated : Microsoft.EntityFrameworkCore.DbSet<'Entity (requires 'Entity : null)> * FormattableString -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
<Extension()>
Public Function FromSqlInterpolated(Of TEntity As Class) (source As DbSet(Of TEntity), sql As FormattableString) As IQueryable(Of TEntity)

類型參數

TEntity

元素 source的類型。

參數

source
DbSet<TEntity>

用 an IQueryable<T> 作為插值字串 SQL 查詢的基底(通常是 DbSet<TEntity>。

sql
FormattableString

插值字串代表帶有參數的 SQL 查詢。

傳回

IQueryable<TEntity>

表示 IQueryable<T> 插值字串 SQL 查詢。

屬性

備註

如果資料庫提供者支援在提供的 SQL 上編寫,你可以使用 LINQ 運算子在原始 SQL 查詢上編寫。

和任何接受 SQL 的 API 一樣,必須對使用者輸入進行參數化,以防止 SQL 注入攻擊。 你可以在 SQL 查詢字串中加入插值參數的佔位符。 你提供的任何插值參數值都會自動轉換成 DbParameter。

更多資訊與範例請參閱「 使用 EF Core 執行原始 SQL 指令 」。

適用於