This documentation is archived and is not being maintained.

ObjectParameterCollection Class

Represents the query parameters as ObjectParameter objects that are defined in an ObjectQuery(Of T).

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

'Declaration
Public NotInheritable Class ObjectParameterCollection _
	Implements ICollection(Of ObjectParameter), IEnumerable(Of ObjectParameter),  _
	IEnumerable
'Usage
Dim instance As ObjectParameterCollection

Represents the query parameters as ObjectParameter objects defined in an ObjectQuery(Of T).

This class cannot be inherited.

The parameters that are passed to query builder methods are aggregated by successive instances of an ObjectQuery(Of 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 advWorksContext As New AdventureWorksEntities
    Try 
        Dim queryString As String = _
            "SELECT VALUE Contact FROM AdventureWorksEntities.Contact " & _
            "AS Contact WHERE Contact.LastName = @ln AND Contact.FirstName = @fn" 

        Dim contactQuery As New ObjectQuery(Of Contact)(queryString, advWorksContext)

        ' 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
        Console.WriteLine("Count is {0}.", objectParameterCollection.Count)

        ' Iterate through the ObjectParameterCollection collection. 
        Dim result As ObjectParameter
        For Each result In DirectCast(objectParameterCollection,  _
            IEnumerable(Of ObjectParameter))
            Console.WriteLine("{0} {1} {2}", result.Name, result.Value, _
                              result.ParameterType)
        Next 
    Catch ex As EntitySqlException
        Console.WriteLine(ex.ToString)
    End Try 
End Using

System.Object
  System.Data.Objects.ObjectParameterCollection

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
Show: