ObjectParameterCollection.Remove(ObjectParameter) ObjectParameterCollection.Remove(ObjectParameter) ObjectParameterCollection.Remove(ObjectParameter) ObjectParameterCollection.Remove(ObjectParameter) Method

定义

按引用从集合中移除 ObjectParameter 的实例(如果集合中存在该实例)。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

参数

parameter
ObjectParameter ObjectParameter ObjectParameter ObjectParameter

要从集合中移除的对象。An object to remove from the collection.

返回

如果找到参数对象且已从集合中删除该对象,则为 true;否则为 falsetrue if the parameter object was found and removed from the collection; otherwise, false.

实现

异常

parameter 参数为 nullThe parameter argument is null.

示例

本主题中的示例基于AdventureWorks 销售模型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);
}
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 ObjectQuery's Parameters collection. 
    contactQuery.Parameters.Add(New ObjectParameter("ln", "Adams"))
    contactQuery.Parameters.Add(New ObjectParameter("fn", "Frances"))

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

    Dim objectParameter As ObjectParameter = objectParameterCollection("ln")

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

注解

这是基于引用的比较。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.

适用于