Provides facilities for querying and working with entity data as objects.
Namespace:
System.Data.Objects
Assembly:
System.Data.Entity (in System.Data.Entity.dll)
Visual Basic (Declaration)
Public Class ObjectContext _
Implements IDisposable
Dim instance As ObjectContext
public class ObjectContext : IDisposable
public ref class ObjectContext : IDisposable
public class ObjectContext implements IDisposable
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:
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
// Create the ObjectContext.
ObjectContext context =
new ObjectContext("name=AdventureWorksEntities");
// Set the DefaultContainerName for the ObjectContext.
context.DefaultContainerName = "AdventureWorksEntities";
ObjectQuery<Product> query = new ObjectQuery<Product>("Product", context);
// Iterate through the collection of Products.
foreach (Product result in query)
Console.WriteLine("Product Name: {0}", result.Name);
System..::.Object
System.Data.Objects..::.ObjectContext
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
Reference
Other Resources