ObjectQuery.Parameters Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the parameter collection for this object query.

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

Public ReadOnly Property Parameters As ObjectParameterCollection

Property Value

Type: System.Data.Objects.ObjectParameterCollection

The parameter collection for this ObjectQuery(Of T).

Use the returned ObjectParameterCollection to specify parameters that are passed to the query. For more information, see Query Builder Methods.

This example is based on the AdventureWorks Sales Model. The example adds new parameters to the collection and then gets the parameter collection for this ObjectQuery(Of T). Then it iterates through the ObjectParameterCollection and displays the name, type, and value of each parameter in the collection.

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

    ' Iterate through the ObjectParameterCollection. 
    For Each result As ObjectParameter In objectParameterCollection
        Console.WriteLine("{0} {1} {2}", result.Name, result.Value, result.ParameterType)
    Next
End Using

.NET Framework
Available since 3.5
Return to top
Show: