ObjectParameterCollection.Remove Method (ObjectParameter)

 

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.

Exception Condition
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 AdventureWorks 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
Available since 3.5
Return to top
Show: