Chapter 3. Integrating Entity Framework and ASP.NET

 

This chapter covers

  • Handling the context in ASP.NET applications
  • Optimizing persistence in ASP.NET applications
  • Managing concurrency
  • Optimizing performance

In the previous chapter, we talked about the different ways you can design your application. We focused mainly on data access code, and you discovered how using Entity Framework might save your life.

In this chapter, we’ll look at integrating Entity Framework and ASP.NET. You’ll see some of the techniques you learned in the previous chapter and how to use them in this environment. You’ll learn how to handle context instantiation and destruction to achieve the best performance and design. You’ll also learn how to persist modifications made in an ASP.NET page in the database, and we’ll give you a few tips about performance. To be in sync with the previous chapter, all examples use the Northwind database to show how to integrate Entity Framework and ASP.NET.

Do you remember the ObjectContext class (a.k.a context) from the previous chapter? It’s the class where the Entity Framework magic begins. We’ll start by talking about the most important concept of this class in ASP.NET applications: lifetime. We’re starting with the basics because if you ignore the foundation, your applications might be slow or even crash.

3.1. Understanding context lifetime

3.2. Using the context the right way

3.3. Optimizing performance in an ASP.NET environment

3.4. Summary