Working with Object Context in the ADO.NET Entity Framework : Page 3
Take advantage of the Object Context in Entity Framework to perform CRUD operations and attach or detach entities.
by Joydip Kanjilal
Jan 20, 2012
Page 3 of 3
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
if (_objectContext == null)
_objectContext = new AdventureWorksObjectContext();
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.
Joydip Kanjilal has over 10 years of industry experience with C, C++, Java, C#, VB, VC++, ASP.Net, XML, Design Patterns, UML, etc. He currently works as a senior project leader in a reputable multinational company in Hyderabad, India, and has contributed articles on .NET and related technologies to www.aspalliance.com.