Edit

Share via


ObjectParameterCollection.Remove(ObjectParameter) Method

Definition

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

public:
 virtual bool Remove(System::Data::Objects::ObjectParameter ^ parameter);
public bool Remove (System.Data.Objects.ObjectParameter parameter);
abstract member Remove : System.Data.Objects.ObjectParameter -> bool
override this.Remove : System.Data.Objects.ObjectParameter -> bool
Public Function Remove (parameter As ObjectParameter) As Boolean

Parameters

parameter
ObjectParameter

An object to remove from the collection.

Returns

true if the parameter object was found and removed from the collection; otherwise, false.

Implements

Exceptions

The parameter argument is null.

Examples

This 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);
}

Remarks

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.

Applies to