ObjectParameterCollection.Remove(ObjectParameter) 方法

定義

如果集合中存在 ,則透過參考從集合中移除 。ObjectParameter

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

一個物件,要從收藏中移除。

傳回

true如果參數物件被找到並從集合中移除;否則,。 false

實作

例外狀況

parameter 點為 null

範例

此範例為集合新增兩個參數,然後移除這些參數。

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

備註

這是一個基於參考的比較。 也就是說,如果指定一個查詢參數物件,且其名稱與集合中的參數物件相同,則該集合中的參數只有在與該物件相同時才會被移除。 要依名稱移除物件,先使用索引器取得參數實例,然後使用此方法移除。

適用於