Export (0) Print
Expand All

ObjectParameterCollection.CopyTo Method

Allows the parameters in the collection to be copied into a supplied array, starting with the object at the specified index.

Namespace:  System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public void CopyTo(
	ObjectParameter[] array,
	int index
)

Parameters

array
Type: System.Data.Objects.ObjectParameter[]

The array into which to copy the parameters.

index
Type: System.Int32

The index in the array at which to start copying the parameters.

Implements

ICollection<T>.CopyTo(T[], Int32)

The example in this topic is based on the Adventure Works Sales Model. 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);
    }
}

.NET Framework

Supported in: 4.6, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft