ObjectParameterCollection.Count ObjectParameterCollection.Count ObjectParameterCollection.Count ObjectParameterCollection.Count Property

Definition

Ruft die aktuelle Anzahl der Parameter in der Auflistung ab.Gets the number of parameters currently in the collection.

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

Eigenschaftswert

Die Anzahl der aktuell in der Auflistung enthaltenen ObjectParameter-Objekte.The number of ObjectParameter objects that are currently in the collection.

Implementiert

Beispiele

Das Beispiel in diesem Thema basiert auf dem AdventureWorks Sales-Modell.The example in this topic is based on the AdventureWorks Sales Model. In diesem Beispiel werden der Auflistung neue Parameter hinzugefügt, und die Anzahl der Parameter in der Auflistung wird abgerufen.The example adds new parameters to the collection and gets the count of the parameters in the collection. 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;

    Console.WriteLine("Count is {0}.", objectParameterCollection.Count);

    // Iterate through the ObjectParameterCollection collection.
    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

    Console.WriteLine("Count is {0}.", objectParameterCollection.Count)

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

Gilt für:

Siehe auch