This documentation is archived and is not being maintained.

ObjectParameterCollection Class

Represents the query parameters as ObjectParameter objects that are defined in an ObjectQuery<T>.

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

public sealed class ObjectParameterCollection : ICollection<ObjectParameter>, 
	IEnumerable<ObjectParameter>, IEnumerable

Represents the query parameters as ObjectParameter objects defined in an ObjectQuery<T>.

This class cannot be inherited.

The parameters that are passed to query builder methods are aggregated by successive instances of an ObjectQuery<T> in the sequence. They can be accessed by using the Parameters property, which returns the ObjectParameterCollection. After parameters have been added, they can be removed from the collection and the collection can be cleared, as long as the query has not been compiled or executed. Parameter names cannot be changed, but values can be changed at any time.

Parameters must be unique in the ObjectParameterCollection. There cannot be two parameters in the collection with the same name.

When using composition methods, such as Union, UnionAll, Intersect and Except, the parameters are merged. An exception is thrown when the sets of parameters are incompatible or incomplete. For more information, see Query Builder Methods (Entity Framework).

The example in this topic is based on the Adventure Works Sales Model. The example adds new parameters to the collection and gets the count of the parameters in the collection. Then it iterates through the ObjectParameterCollection and displays the name, type, and value of each parameter in the collection.

using (AdventureWorksEntities advWorksContext =
    new AdventureWorksEntities())
        string queryString =
            @"SELECT VALUE Contact FROM AdventureWorksEntities.Contact 
            AS Contact WHERE Contact.LastName = @ln AND Contact.FirstName = @fn";

        ObjectQuery<Contact> contactQuery =
            new ObjectQuery<Contact>(queryString, advWorksContext);

        // Add parameters to the collection.
        contactQuery.Parameters.Add(new ObjectParameter("ln", "Adams"));
        contactQuery.Parameters.Add(new ObjectParameter("fn", "Frances"));

        ObjectParameterCollection objectParameterCollection = 

        Console.WriteLine("Count is {0}.", objectParameterCollection.Count);

        // Iterate through the ObjectParameterCollection collection. 
        foreach (ObjectParameter result in objectParameterCollection)
            Console.WriteLine("{0} {1} {2}", result.Name,
    catch (EntitySqlException ex)


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5 SP1