語言

RelationalQueryableExtensions 類別

定義

針對 LINQ 查詢的關聯式資料庫專用擴充方法。

public static class RelationalQueryableExtensions
[System.Runtime.CompilerServices.Nullable(0)]
public static class RelationalQueryableExtensions
type RelationalQueryableExtensions = class
[<System.Runtime.CompilerServices.Nullable(0)>]
type RelationalQueryableExtensions = class
Public Module RelationalQueryableExtensions
繼承
RelationalQueryableExtensions
屬性

方法

名稱 Description
AsSingleQuery<TEntity>(IQueryable<TEntity>)

回傳一個新查詢,該查詢設定為將查詢結果中的集合匯入單一資料庫查詢。

AsSplitQuery<TEntity>(IQueryable<TEntity>)

回傳一個新查詢,並設定為透過獨立資料庫查詢載入查詢結果中的集合。

CreateDbCommand(IQueryable)

建立 DbCommand 一個設定來執行這個查詢。

ExecuteDelete<TSource>(IQueryable<TSource>)

刪除所有與 LINQ 查詢相符實體實例的資料庫列。

ExecuteDeleteAsync<TSource>(IQueryable<TSource>, CancellationToken)

非同步刪除與 LINQ 查詢相符的實體實例的資料庫列。

ExecuteUpdate<TSource>(IQueryable<TSource>, Expression<Func<SetPropertyCalls<TSource>,SetPropertyCalls<TSource>>>)

更新所有與資料庫 LINQ 查詢相符實體實例的資料庫資料列。

ExecuteUpdateAsync<TSource>(IQueryable<TSource>, Expression<Func<SetPropertyCalls<TSource>,SetPropertyCalls<TSource>>>, CancellationToken)

非同步更新與資料庫 LINQ 查詢相符實體實例的資料庫列。

FromSql<TEntity>(DbSet<TEntity>, FormattableString)

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

FromSql<TEntity>(IQueryable<TEntity>, FormattableString)
已淘汰.

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

如果資料庫提供者支援在提供的 SQL 上撰寫,你可以使用 LINQ 運算子 - context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)在原始 SQL 查詢上進行組合。

和任何接受 SQL 的 API 一樣,必須對使用者輸入進行參數化,以防止 SQL 注入攻擊。 你可以在 SQL 查詢字串中加入插值參數的佔位符。 你提供的任何插值參數值都會自動轉換成 DbParameter - context.Blogs.FromSql($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")。

FromSql<TEntity>(IQueryable<TEntity>, RawSqlString, Object[])
已淘汰.

根據原始 SQL 查詢建立 LINQ 查詢。

如果資料庫提供者支援在提供的 SQL 上撰寫,你可以使用 LINQ 運算子 - context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)在原始 SQL 查詢上進行組合。

和任何接受 SQL 的 API 一樣,必須對使用者輸入進行參數化,以防止 SQL 注入攻擊。 你可以在 SQL 查詢字串中加入參數佔位符,然後以參數值作為額外參數。 你提供的任何參數值都會自動轉換成 DbParameter - context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)。

此超載同時接受 DbParameter 實例作為參數值。 這讓你可以在 SQL 查詢字串中使用命名參數—— context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))

FromSql<TEntity>(IQueryable<TEntity>, String, Object[])

根據原始 SQL 查詢建立 LINQ 查詢。

如果資料庫提供者支援在提供的 SQL 上撰寫,你可以使用 LINQ 運算子 - context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)在原始 SQL 查詢上進行組合。

和任何接受 SQL 的 API 一樣,必須對使用者輸入進行參數化,以防止 SQL 注入攻擊。 你可以在 SQL 查詢字串中加入參數佔位符,然後以參數值作為額外參數。 你提供的任何參數值都會自動轉換成 DbParameter - context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)。

你也可以建構一個 DbParameter,並以參數值提供給 。 這讓你可以在 SQL 查詢字串中使用命名參數—— context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))

FromSqlInterpolated<TEntity>(DbSet<TEntity>, FormattableString)
已淘汰.

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

FromSqlRaw<TEntity>(DbSet<TEntity>, String, Object[])

根據原始 SQL 查詢建立 LINQ 查詢。

適用於