ObjectContext Class
Provides facilities for querying and working with entity data as objects.
Assembly: System.Data.Entity (in System.Data.Entity.dll)
The ObjectContext class is the primary class for interacting with data as objects that are instances of entity types that are defined in an Entity Data Model (EDM). An instance of the ObjectContext class encapsulates the following:
A connection to the database, in the form of an EntityConnection object.
Metadata that describes the model, in the form of a MetadataWorkspace object.
An ObjectStateManager object that manages objects persisted in the cache.
When the object layer that represents the conceptual model of an EDM is generated by the Entity Data Model tools, the class that represents the EntityContainer for the model is derived from the ObjectContext. For more information, see Object Services Overview (Entity Framework).
This example is based on the Adventure Works Sales Model. The example shows you how to construct an ObjectContext.
' Create the ObjectContext. Dim context As ObjectContext = _ New ObjectContext("name=AdventureWorksEntities") ' Set the DefaultContainerName for the ObjectContext. context.DefaultContainerName = "AdventureWorksEntities" Dim query As ObjectQuery(Of Product) = _ New ObjectQuery(Of Product)("Product", context) ' Iterate through the collection of Products. Dim result As Product For Each result In query Console.WriteLine("Product Name: {0}", result.Name) Next
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.