ObjectQuery.Parameters Property

Definition

Ruft die Parameterauflistung für diese Objektabfrage ab.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

Property Value

ObjectParameterCollection

Die Parameterauflistung für diese ObjectQuery<T>.The parameter collection for this ObjectQuery<T>.

Examples

Dieses Beispiel basiert auf den Microsoft SQL Server Product Samples: Database.This example is based on the Microsoft SQL Server Product Samples: Database. In diesem Beispiel werden der Auflistung neue Parameter hinzugefügt und dann die Parameterauflistung für diese ObjectQuery<T> abgerufen.The example adds new parameters to the collection and then gets the parameter collection for this ObjectQuery<T>. Daraufhin wird die ObjectParameterCollection durchlaufen, und für jeden Parameter in der Auflistung werden Name, Typ und Wert angezeigt.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

Remarks

Geben Sie Parameter, die an die Abfrage übergeben werden, mit der zurückgegebenen ObjectParameterCollection an.Use the returned ObjectParameterCollection to specify parameters that are passed to the query. Weitere Informationen finden Sie unter Abfrage-Generator-Methoden.For more information, see Query Builder Methods.

Applies to

See also