แก้ไข

แชร์ผ่าน


ObjectParameterCollection.Contains Method

Definition

Checks for the existence of a specified ObjectParameter in the collection by reference.

Overloads

Contains(ObjectParameter)

Checks for the existence of a specified ObjectParameter in the collection by reference.

Contains(String)

Determines whether an ObjectParameter with the specified name is in the collection.

Contains(ObjectParameter)

Checks for the existence of a specified ObjectParameter in the collection by reference.

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

Parameters

parameter
ObjectParameter

The ObjectParameter to find in the collection.

Returns

true if the parameter object was found in the collection; otherwise, false.

Implements

Exceptions

The parameter argument is null.

Remarks

This is a reference-based check. That is, if an ObjectParameter is specified that contains the same name as a parameter object in the collection, this method will only return true if it is the same object.

Applies to

Contains(String)

Determines whether an ObjectParameter with the specified name is in the collection.

public:
 bool Contains(System::String ^ name);
public bool Contains (string name);
member this.Contains : string -> bool
Public Function Contains (name As String) As Boolean

Parameters

name
String

The name of the parameter to look for in the collection. This name should not include the "@" parameter marker that is used in the Entity SQL statements, only the actual name.

Returns

true if a parameter with the specified name was found in the collection; otherwise, false.

Exceptions

The name parameter is null.

Examples

This example uses the Contains method to determine whether the specified parameter is in the collection.

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 collection.
    contactQuery.Parameters.Add(new ObjectParameter("ln", "Adams"));
    contactQuery.Parameters.Add(new ObjectParameter("fn", "Frances"));

    ObjectParameterCollection objectParameterCollection =
        contactQuery.Parameters;

    if (objectParameterCollection.Contains("ln"))
        Console.WriteLine("ln is here");
    else
        Console.WriteLine("ln is not here");
}

Applies to