Chapter 1. Introducing the DbContext API
Since its first release, the most critical element in Entity Framework
has been the ObjectContext. It is this
class that allows us to interact with a database using a conceptual model.
The context lets us express and execute queries, track changes to objects
and persist those changes back to the database. The ObjectContext class interacts with other important
Entity Framework classes such as the ObjectSet, which enables set operations on our
entities in memory, and ObjectQuery,
which is the brains behind executing queries. All of these classes are
replete with features and functionality—some of it complex and much of it
only necessary for special cases. After two iterations of Entity Framework
(in .NET 3.5 SP1 and .NET 4) it was clear that developers were most commonly
using a subset of the features, and unfortunately, some of the tasks we
needed to do most frequently were difficult to discover and code.
Recognizing this, the Entity Framework team set out to make it easier
for developers to access the most frequently used patterns for working with
objects within Entity Framework. Their solution was a new set of classes
that encapsulate this subset of ObjectContext features. These new classes use the
ObjectContext behind the scenes, but
developers can work with them without having to tangle with the ObjectContext unless they need to specifically use some of the more advanced features. The new set of classes was originally released as part of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access