ObjectQuery.Parameters 屬性


取得這個物件查詢的參數集合。Gets the parameter collection for this object query.

 property System::Data::Objects::ObjectParameterCollection ^ Parameters { System::Data::Objects::ObjectParameterCollection ^ get(); };
public System.Data.Objects.ObjectParameterCollection Parameters { get; }
member this.Parameters : System.Data.Objects.ObjectParameterCollection
Public ReadOnly Property Parameters As ObjectParameterCollection



這個 ObjectQuery<T> 的參數集合。The parameter collection for this ObjectQuery<T>.


這個範例是根據 Microsoft SQL Server 產品範例: DatabaseThis example is based on the Microsoft SQL Server Product Samples: Database. 此範例會將新的參數加入至集合,並且取得這個 ObjectQuery<T> 的參數集合。The example adds new parameters to the collection and then gets the parameter collection for this ObjectQuery<T>. 然後,它會逐一查看 ObjectParameterCollection 並顯示集合中每個參數的名稱、型別和值。Then it iterates through the ObjectParameterCollection and displays the name, type, and value of each parameter in the collection.

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
    string queryString =
        @"SELECT VALUE contact FROM AdventureWorksEntities.Contacts
        AS contact WHERE contact.LastName = @ln
        AND contact.FirstName = @fn";

    ObjectQuery<Contact> contactQuery =
        new ObjectQuery<Contact>(queryString, context);

    // Add parameters to the collection.
    contactQuery.Parameters.Add(new ObjectParameter("ln", "Adams"));
    contactQuery.Parameters.Add(new ObjectParameter("fn", "Frances"));

    ObjectParameterCollection objectParameterCollection =

    // Iterate through the ObjectParameterCollection.
    foreach (ObjectParameter result in objectParameterCollection)
        Console.WriteLine("{0} {1} {2}", result.Name,
Using context As New AdventureWorksEntities()
    Dim queryString As String = "SELECT VALUE contact FROM AdventureWorksEntities.Contacts" & _
            " AS contact WHERE contact.LastName = @ln AND contact.FirstName = @fn"

    Dim contactQuery As New ObjectQuery(Of Contact)(queryString, context)

    ' Add parameters to the collection. 
    contactQuery.Parameters.Add(New ObjectParameter("ln", "Adams"))
    contactQuery.Parameters.Add(New ObjectParameter("fn", "Frances"))

    Dim objectParameterCollection As ObjectParameterCollection = contactQuery.Parameters

    ' Iterate through the ObjectParameterCollection. 
    For Each result As ObjectParameter In objectParameterCollection
        Console.WriteLine("{0} {1} {2}", result.Name, result.Value, result.ParameterType)
End Using


您可以使用傳回的 ObjectParameterCollection 來指定傳遞給查詢的參數。Use the returned ObjectParameterCollection to specify parameters that are passed to the query. 如需詳細資訊,請參閱查詢產生器 方法For more information, see Query Builder Methods.