Edit

Share via


ObjectQuery.Parameters Property

Definition

Gets the parameter collection for this object query.

public:
 property System::Data::Objects::ObjectParameterCollection ^ Parameters { System::Data::Objects::ObjectParameterCollection ^ get(); };
public System.Data.Objects.ObjectParameterCollection Parameters { get; }
member this.Parameters : System.Data.Objects.ObjectParameterCollection
Public ReadOnly Property Parameters As ObjectParameterCollection

Property Value

The parameter collection for this ObjectQuery<T>.

Examples

This example adds new parameters to the collection and then gets the parameter collection for this ObjectQuery<T>. Then it iterates through the ObjectParameterCollection and displays the name, type, and value of each parameter 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;

    // Iterate through the ObjectParameterCollection.
    foreach (ObjectParameter result in objectParameterCollection)
    {
        Console.WriteLine("{0} {1} {2}", result.Name,
            result.Value,
            result.ParameterType);
    }
}

Remarks

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

Applies to

See also