ObjectQuery.Context Proprietà

Definizione

Ottiene il contesto dell'oggetto associato a questa query di oggetto.

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

Valore della proprietà

Oggetto ObjectContext associato all'istanza di ObjectQuery<T>.

Esempio

Questo esempio ottiene l'oggetto ObjectContext associato a questo ObjectQuery<T> oggetto.

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);
}

Commenti

Il contesto per la query include connessione, cache e metadati. Per altre informazioni, vedere Cenni preliminari su Object Services (Entity Framework).

La proprietà di connessione è modificabile e deve essere impostata prima di potere eseguire una query. Per altre informazioni, vedere Gestione di Connections in Object Services (Entity Framework).

Si applica a

Vedi anche