ObjectParameterCollection.Contains Method (String)

 

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

Namespace:   System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public bool Contains(
	string name
)

Parameters

name
Type: System.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.

Return Value

Type: System.Boolean

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

Exception Condition
ArgumentNullException

The name parameter is null.

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

.NET Framework
Available since 3.5
Return to top
Show: