Chapter 27. Building Layered Web Applications

In Chapter 12, you learned how to create websites using Entity Framework’s ASP.NET EntityDataSource control. While this approach is fast, it uses data access code that is tied directly to the user interface. You’ve since learned a lot more about working with the Entity Framework, so we’ll finish this book with a look at some better ways to use entities in better architected web applications. Several of these techniques are new to Entity Framework in .NET 4. The introduction of POCO support enables many new possibilities, such as the use of the repositories you built in Chapter 24. Foreign keys and the new state modification methods (e.g., ObjectStateManager.ChangeState) provide more control when working with EntityObject or POCO entities.

In this chapter, you’ll first learn about the life cycle of web pages in a web application and how that impacts some of the choices you will have to make when planning to use the Entity Framework as your data access layer in a tiered application. Then you will build two very different types of web applications, though both will take advantage of the repositories from Chapter 24.

The first will be an ASP.NET Web Forms application where you can take advantage of ASP.NET’s Session and ViewState features to retain object data across postbacks.

The second will use classes in a simple ASP.NET Model-View-Controller (MVC) application. Many introductory demos of MVC using Entity Framework place the ObjectContext ...

Get Programming Entity Framework, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.