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.

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

The example in this topic is based on the AdventureWorks Sales Model. The 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");
}
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 collection. 
    contactQuery.Parameters.Add(New ObjectParameter("ln", "Adams"))
    contactQuery.Parameters.Add(New ObjectParameter("fn", "Frances"))

    Dim objectParameterCollection As ObjectParameterCollection = contactQuery.Parameters

    If objectParameterCollection.Contains("ln") Then
        Console.WriteLine("ln is here")
    Else
        Console.WriteLine("ln is not here")
    End If
End Using

Applies to