In this chapter we’ll explore the two different approaches for manipulating an Entity Data Model in code.
We’ll start by exploring the older of the two APIs: the ObjectContext
API. The code produced by the Database-First and Model-First Workflows uses this API by default, and the DbContext
wraps its functionality, so a basic understanding will be useful even if you decide you prefer the newer (and Microsoft-recommended) DbContext
API.
After we’ve found our way around the original ObjectContext
API, we’ll turn our attention to the newer DbContext
API that simplifies a lot of the common tasks you’ll need to perform. We’ll also get our first glimpse at how you can control the code produced by the Entity Model Designer, a topic we’ll explore in more detail in the next chapter.
Finally we’ll look at how you can extend the model created by the designer to add new properties that aren’t mapped to the database field, or new functionality that is purely code-based.