This documentation is archived and is not being maintained.

ObjectParameterCollection.Remove Method

Removes an instance of an ObjectParameter from the collection by reference if it exists in the collection.

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

public bool Remove(
	ObjectParameter parameter
)

Parameters

parameter
Type: System.Data.Objects.ObjectParameter
An object to remove from the collection.

Return Value

Type: System.Boolean
Returns true if the parameter object was found and removed from the collection; otherwise, false.

Implements

ICollection<T>.Remove(T)

ExceptionCondition
ArgumentNullException

The parameter argument is null.

This is a reference-based comparison. That is, if a query parameter object is specified that contains the same name as a parameter object in the collection, the parameter in the collection will only be removed if it is the same object. To remove an object by name, first use the indexer to retrieve the parameter instance, then remove it by using this method.

The example in this topic is based on the Adventure Works Sales Model. The example adds two parameters to the collection and then removes the parameters.


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 ObjectQuery's Parameters collection.
    contactQuery.Parameters.Add(new ObjectParameter("ln", "Adams"));
    contactQuery.Parameters.Add(new ObjectParameter("fn", "Frances"));

    ObjectParameterCollection objectParameterCollection =
        contactQuery.Parameters;
    Console.WriteLine("Count before Remove is called: {0}",
        objectParameterCollection.Count);

    ObjectParameter objectParameter = objectParameterCollection["ln"];

    // Remove the specified parameter from the collection.
    objectParameterCollection.Remove(objectParameter);
    Console.WriteLine("Count after Remove is called: {0}",
        objectParameterCollection.Count);
}


.NET Framework

Supported in: 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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