Uređivanje

Dijeli putem


ObjectParameter.Value Property

Definition

Gets or sets the parameter value.

public:
 property System::Object ^ Value { System::Object ^ get(); void set(System::Object ^ value); };
public object Value { get; set; }
member this.Value : obj with get, set
Public Property Value As Object

Property Value

The parameter value.

Examples

This example adds new parameters to the collection. It iterates through the ObjectParameterCollection and displays the name, the type and the 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

After the query has been compiled, the value cannot be changed. For more information, see Query Builder Methods.

If the new value is incompatible with the type declared in the constructor, it might cause a run-time exception. The provider must determine whether the value is compatible with the declared type. For example, if the initial type is Int32 and the new value is Guid, you might receive an exception.

Applies to

See also