Share via


DbQuery 類別

[此頁面專屬於 Entity Framework 第 6 版。最新版本可從 'Entity Framework' NuGet 套件取得。如需 Entity Framework 的詳細資訊,請參閱 msdn.com/data/ef。]

表示針對 DbContext 的非泛型 LINQ to Entities 查詢。

繼承階層

System.Object
  System.Data.Entity.Infrastructure.DbQuery
    System.Data.Entity.DbSet

命名空間:  System.Data.Entity.Infrastructure
組件:  EntityFramework (在 EntityFramework.dll 中)

語法

'宣告
<SuppressMessageAttribute("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")> _
<SuppressMessageAttribute("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")> _
Public MustInherit Class DbQuery _
    Implements IOrderedQueryable, IQueryable, IEnumerable, IListSource,  _
    IDbAsyncEnumerable
'用途
Dim instance As DbQuery
[SuppressMessageAttribute("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
[SuppressMessageAttribute("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
public abstract class DbQuery : IOrderedQueryable, 
    IQueryable, IEnumerable, IListSource, IDbAsyncEnumerable
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1010:CollectionsShouldImplementGenericInterface")]
[SuppressMessageAttribute(L"Microsoft.Naming", L"CA1710:IdentifiersShouldHaveCorrectSuffix")]
public ref class DbQuery abstract : IOrderedQueryable, 
    IQueryable, IEnumerable, IListSource, IDbAsyncEnumerable
[<AbstractClassAttribute>]
[<SuppressMessageAttribute("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")>]
[<SuppressMessageAttribute("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")>]
type DbQuery =  
    class 
        interface IOrderedQueryable 
        interface IQueryable 
        interface IEnumerable 
        interface IListSource 
        interface IDbAsyncEnumerable 
    end
public abstract class DbQuery implements IOrderedQueryable, IQueryable, IEnumerable, IListSource, IDbAsyncEnumerable

DbQuery 類型會公開下列成員。

屬性

  名稱 描述
公用屬性 ElementType IQueryable 元素類型。

靠上

方法

  名稱 描述
公用方法 AsNoTracking 傳回新的查詢,其中傳回的實體將不會在 DbContext 中快取。
公用方法 AsStreaming 已過時。 傳回會串流結果而非緩衝處理的新查詢。
公用方法 Cast<TElement> 傳回相等的泛型 DbQuery<TResult> 物件。
公用方法 Equals 指定此查詢是否與指定的物件相等。 (覆寫 Object.Equals(Object)。)
受保護的方法 Finalize (繼承自 Object)。
公用方法 GetHashCode 取得與此查詢相關聯的雜湊碼。 (覆寫 Object.GetHashCode()。)
公用方法 GetType 取得與此查詢相關聯的類型。
公用方法 Include 指定要包含在查詢結果中的相關物件。
受保護的方法 MemberwiseClone (繼承自 Object)。
公用方法 ToString 傳回基礎查詢的 String 表示法。 (覆寫 Object.ToString()。)

靠上

擴充方法

  名稱 描述
公用擴充方法 ForEachAsync(Action<Object>) 多載。 非同步列舉查詢結果,並針對每個項目執行指定動作。 (以 QueryableExtensions 定義。)
公用擴充方法 ForEachAsync(Action<Object>, CancellationToken) 多載。 非同步列舉查詢結果,並針對每個項目執行指定動作。 (以 QueryableExtensions 定義。)
公用擴充方法 Load 列舉查詢,這樣一來,針對類似 DbSet<TEntity>ObjectSet<TEntity>ObjectQuery<T> 和其他的伺服器查詢而言,查詢結果將會載入相關聯的 DbContextObjectContext 或用戶端的其他快取中。這相當於呼叫 ToList 然後捨棄此清單,而沒有實際建立此清單的負荷。 (以 QueryableExtensions 定義。)
公用擴充方法 LoadAsync() 多載。 非同步列舉查詢,這樣一來,針對類似 DbSet<TEntity>ObjectSet<TEntity>ObjectQuery<T> 和其他的伺服器查詢而言,查詢結果將會載入相關聯的 DbContextObjectContext 或用戶端的其他快取中。這相當於呼叫 ToList 然後捨棄此清單,而沒有實際建立此清單的負荷。 (以 QueryableExtensions 定義。)
公用擴充方法 LoadAsync(CancellationToken) 多載。 非同步列舉查詢,這樣一來,針對類似 DbSet<TEntity>ObjectSet<TEntity>ObjectQuery<T> 和其他的伺服器查詢而言,查詢結果將會載入相關聯的 DbContextObjectContext 或用戶端的其他快取中。這相當於呼叫 ToList 然後捨棄此清單,而沒有實際建立此清單的負荷。 (以 QueryableExtensions 定義。)
公用擴充方法 ToListAsync() 多載。 透過以非同步方式列舉從 IQueryable 建立 List<T>。 (以 QueryableExtensions 定義。)
公用擴充方法 ToListAsync(CancellationToken) 多載。 透過以非同步方式列舉從 IQueryable 建立 List<T>。 (以 QueryableExtensions 定義。)

靠上

明確介面實作

  名稱 描述
明確介面實作私用屬性 IListSource.ContainsListCollection 傳回 false。
明確介面實作私用屬性 IQueryable.Expression IQueryable LINQ 運算式。
明確介面實作私用方法 IEnumerable.GetEnumerator 傳回 IEnumerator,其在列舉時會對資料庫執行查詢。
明確介面實作私用方法 IListSource.GetList 擲回例外狀況,表示不支援直接繫結至存放區查詢。改為以資料填入 DbSet,例如,藉由使用 Load 擴充方法,然後繫結至本機資料。如果是 WPF,則繫結至 DbSet.Local。如果是 Windows Form,則繫結至 DbSet.Local.ToBindingList()。
明確介面實作私用屬性 IQueryable.Provider IQueryable 提供者。
明確介面實作私用方法 IDbAsyncEnumerable.GetAsyncEnumerator 傳回 IDbAsyncEnumerator,其在列舉時會對資料庫執行查詢。

靠上

執行緒安全

這個類型的任何 Public static (在 Visual Basic 中為 Shared) 成員都是安全執行緒。並非所有的執行個體成員都是安全執行緒。

請參閱

參考

System.Data.Entity.Infrastructure 命名空間