ObjectQuery.Parameters ObjectQuery.Parameters ObjectQuery.Parameters ObjectQuery.Parameters Property

定義

このオブジェクト クエリのパラメーター コレクションを取得します。Gets the parameter collection for this object query.

public:
 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>.

この例は、 AdventureWorks Sales Modelに基づいています。This example is based on the AdventureWorks Sales Model. この例では、新しいパラメーターをコレクションに追加し、この 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 =
        contactQuery.Parameters;

    // Iterate through the ObjectParameterCollection.
    foreach (ObjectParameter result in objectParameterCollection)
    {
        Console.WriteLine("{0} {1} {2}", result.Name,
            result.Value,
            result.ParameterType);
    }
}
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)
    Next
End Using

注釈

クエリに渡すパラメーターを指定するには、返された ObjectParameterCollection を使用します。Use the returned ObjectParameterCollection to specify parameters that are passed to the query. 詳細については、「クエリビルダーメソッド」を参照してください。For more information, see Query Builder Methods.

適用対象

こちらもご覧ください