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

備註

這是以參考為基礎的比較。 也就是說,如果指定的查詢參數物件與集合中的參數物件包含相同名稱,就只會移除位於集合中的參數 (如果它是相同物件的話)。 若要依據名稱移除物件,請先使用索引子來擷取參數執行個體,然後使用這個方法來移除它。

適用於