This topic has not yet been rated - Rate this topic

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.
ExceptionCondition
ArgumentNullException

The name parameter is null.

The example in this topic is based on the Adventure Works 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

Supported in: 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.