共用方式為


ObjectContext.ExecuteStoreQueryAsync<TElement> 方法 (String, String, ExecutionOptions, CancellationToken, Object[])

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

以非同步方式直接針對資料來源執行查詢,並傳回具類型之結果的序列。 此查詢是使用伺服器的原生查詢語言 (例如 SQL) 指定。 如果已指定實體集名稱,內容就會追蹤結果。 如同所有接受 SQL 的應用程式開發介面,任何使用者輸入都務必進行參數化以防範 SQL 插入式攻擊。 您可在 SQL 查詢字串中加入參數預留位置,然後再以其他引數提供參數值。 您所提供的任何參數值都將自動轉換為 DbParameter。 context.ExecuteStoreQueryAsync&lt;Post&gt;("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor);。或者,您也可以建構 DbParameter,再將其提供給 SqlQuery。 如此您便能在 SQL 查詢字串中使用具名參數。 context.ExecuteStoreQueryAsync&lt;Post&gt;("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

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

語法

'宣告
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
Public Overridable Function ExecuteStoreQueryAsync(Of TElement) ( _
    commandText As String, _
    entitySetName As String, _
    executionOptions As ExecutionOptions, _
    cancellationToken As CancellationToken, _
    ParamArray parameters As Object() _
) As Task(Of ObjectResult(Of TElement))
'用途
Dim instance As ObjectContext 
Dim commandText As String 
Dim entitySetName As String 
Dim executionOptions As ExecutionOptions 
Dim cancellationToken As CancellationToken 
Dim parameters As Object()
Dim returnValue As Task(Of ObjectResult(Of TElement))

returnValue = instance.ExecuteStoreQueryAsync(commandText, _
    entitySetName, executionOptions, _
    cancellationToken, parameters)
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public virtual Task<ObjectResult<TElement>> ExecuteStoreQueryAsync<TElement>(
    string commandText,
    string entitySetName,
    ExecutionOptions executionOptions,
    CancellationToken cancellationToken,
    params Object[] parameters
)
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
public:
generic<typename TElement>
virtual Task<ObjectResult<TElement>^>^ ExecuteStoreQueryAsync(
    String^ commandText, 
    String^ entitySetName, 
    ExecutionOptions^ executionOptions, 
    CancellationToken cancellationToken, 
    ... array<Object^>^ parameters
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
abstract ExecuteStoreQueryAsync : 
        commandText:string * 
        entitySetName:string * 
        executionOptions:ExecutionOptions * 
        cancellationToken:CancellationToken * 
        parameters:Object[] -> Task<ObjectResult<'TElement>> 
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
override ExecuteStoreQueryAsync : 
        commandText:string * 
        entitySetName:string * 
        executionOptions:ExecutionOptions * 
        cancellationToken:CancellationToken * 
        parameters:Object[] -> Task<ObjectResult<'TElement>> 
JScript does not support generic types and methods.

類型參數

  • TElement
    結果序列的元素類型。

參數

  • commandText
    類型:System.String
    使用伺服器的原生查詢語言指定的查詢。
  • entitySetName
    類型:System.String
    TResult 類型的實體集。 如果未提供實體集名稱,則不會追蹤結果。
  • parameters
    類型:System.Object[]
    要用於查詢的參數值。 如果使用了輸出參數,在完全讀取結果之前,這些參數的值將無法使用。 這是由於 DbDataReader 的基礎行為所造成,請參閱 https://go.microsoft.com/fwlink/?LinkID=398589 以取得詳細資料。

傳回值

類型:System.Threading.Tasks.Task<ObjectResult<TElement>>
表示非同步作業的工作。工作結果包含 TElement 類型的物件列舉。

備註

不支援相同內容執行個體上的多個作用中作業。 使用 'await' 確保在此內容上呼叫另一個方法之前,所有非同步作業都已完成。

請參閱

參考

ObjectContext 類別

ExecuteStoreQueryAsync 多載

System.Data.Entity.Core.Objects 命名空間