ObjectParameterCollection.CopyTo(ObjectParameter[], Int32) ObjectParameterCollection.CopyTo(ObjectParameter[], Int32) ObjectParameterCollection.CopyTo(ObjectParameter[], Int32) ObjectParameterCollection.CopyTo(ObjectParameter[], Int32) Method

Definition

Ermöglicht das Kopieren der Parameter in der Auflistung, beginnend mit dem Objekt am angegebenen Index, in ein angegebenes Array.Allows the parameters in the collection to be copied into a supplied array, starting with the object at the specified index.

public:
 virtual void CopyTo(cli::array <System::Data::Objects::ObjectParameter ^> ^ array, int index);
public void CopyTo (System.Data.Objects.ObjectParameter[] array, int index);
abstract member CopyTo : System.Data.Objects.ObjectParameter[] * int -> unit
override this.CopyTo : System.Data.Objects.ObjectParameter[] * int -> unit
Public Sub CopyTo (array As ObjectParameter(), index As Integer)

Parameter

array
ObjectParameter[]

Das Array, in das die Parameter kopiert werden sollen.The array into which to copy the parameters.

index
Int32 Int32 Int32 Int32

Der Index im Array, von dem ab die Parameter kopiert werden sollen.The index in the array at which to start copying the parameters.

Beispiele

Das Beispiel in diesem Thema basiert auf dem AdventureWorks Sales-Modell.The example in this topic is based on the AdventureWorks Sales Model. Im Beispiel werden die Parameter in das angegebene Array kopiert.The example copies the parameters into the specified array.

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;
    ObjectParameter[] objectParameterArray =
        new ObjectParameter[objectParameterCollection.Count];

    objectParameterCollection.CopyTo(objectParameterArray, 0);

    // Iterate through the ObjectParameter array.
    for (int i = 0; i < objectParameterArray.Length; i++)
    {
        Console.WriteLine("Name: {0} Type: {1} Value: {2}",
            objectParameterArray[i].Name,
            objectParameterArray[i].ParameterType,
            objectParameterArray[i].Value);
    }
}
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
    Dim objectParameterArray As ObjectParameter() = New ObjectParameter(objectParameterCollection.Count - 1) {}

    objectParameterCollection.CopyTo(objectParameterArray, 0)

    ' Iterate through the ObjectParameter array. 
    For i As Integer = 0 To objectParameterArray.Length - 1
        Console.WriteLine("Name: {0} Type: {1} Value: {2}", _
                          objectParameterArray(i).Name, objectParameterArray(i).ParameterType, objectParameterArray(i).Value)
    Next
End Using

Gilt für: