This documentation is archived and is not being maintained.

ObjectParameter Class

Represents a query parameter that is passed to an object query.

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

public sealed class ObjectParameter

Represents a query parameter that is passed to an ObjectQuery<T> or a query builder method. For more information, see Query Builder Methods (Entity Framework).

Object parameters consist of a name, a type, and a value.

This class cannot be inherited. For more information, see ObjectParameterCollection.

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

using (AdventureWorksEntities advWorksContext =
    new AdventureWorksEntities())
{
    try
    {
        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 = 
            contactQuery.Parameters;

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

System.Object
  System.Data.Objects.ObjectParameter

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: