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())
        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 = 

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


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