ObjectQuery.Context ObjectQuery.Context ObjectQuery.Context ObjectQuery.Context Property

Definición

Obtiene el contexto del objeto asociado con esta consulta de objeto.Gets the object context associated with this object query.

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

Valor de propiedad

ObjectContext que está asociado con esta instancia de ObjectQuery<T>.The ObjectContext associated with this ObjectQuery<T> instance.

Ejemplos

El ejemplo de este tema se basa en el modelo AdventureWorks Sales.The example in this topic is based on the AdventureWorks Sales Model. En el ejemplo se obtiene el objeto ObjectContext asociado a este objeto ObjectQuery<T>.The example gets the ObjectContext object associated with this ObjectQuery<T> object.

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString =
        @"SELECT VALUE contact FROM 
        AdventureWorksEntities.Contacts AS contact";

    ObjectQuery<Contact> contactQuery =
        new ObjectQuery<Contact>(queryString,
            context, MergeOption.NoTracking);

    // Get ObjectContext from ObjectQuery.
    ObjectContext objectContext = contactQuery.Context;
    Console.WriteLine("Connection string {0}",
        objectContext.Connection.ConnectionString);
}
Using context As New AdventureWorksEntities()
    Dim queryString As String = "SELECT VALUE contact FROM AdventureWorksEntities.Contacts AS contact"

    Dim contactQuery As New ObjectQuery(Of Contact)(queryString, context, MergeOption.NoTracking)

    ' Get ObjectContext from ObjectQuery. 
    Dim objectContext As ObjectContext = contactQuery.Context
    Console.WriteLine("Connection string {0}", objectContext.Connection.ConnectionString)
End Using

Comentarios

El contexto para la consulta incluye la conexión, la caché y los metadatos.The context for the query includes the connection, cache, and metadata. Para más información, vea Información general de Servicios de objeto (Entity Framework).For more information, see Object Services Overview (Entity Framework).

La propiedad de conexión es mutable y debe establecerse antes de que se pueda ejecutar una consulta.The connection property is mutable and must be set before a query can be executed. Para obtener más información, consulte administrar conexiones en servicios de objeto (Entity Framework).For more information, see Managing Connections in Object Services (Entity Framework).

Se aplica a

Consulte también: