Creating a Shared Object Context
The following code snippet illustrates how you can create a shared Object Context so that it can be globally shared amongst all classes in the application. This is not suitable for ASP.NET applications though.
private static AdventureWorksObjectContext _objectContext;
public AdventureWorksObjectContext ObjectContext
{
get
{
if (_objectContext == null)
_objectContext = new AdventureWorksObjectContext();
return _objectContext;
}
}
Summary
ADO.NET Entity Framework 4.0 is a more mature ORM tool than its predecessors. The new and enhanced features in Entity Framework 4 include, POCO support, Code First Development, Self Tracking Entities, better testability, improved LINQ operator support, improved lazy loading support, and many others. In this article you explored the Object Context in Entity Framework.