Consolidating the Data-Access Code

Most ASP.NET projects have more than one page that needs to use the data model. A common approach to avoiding duplicating the same code is to consolidate the code that deals with the data model into one or more common classes, which are then used by all of the page classes. We will follow this approach before extending the example web application to create, modify, and delete data. Listing 8-9 shows this class, called DataAccess, which contains methods that perform the functionality from the examples so far.

Listing 8-9. The DataAccess class

using System.Collections.Generic; using System.Linq; using System; namespace DataApp {     public static class DataAccess {         ///////////////////////////////

Get Applied ASP.NET 4 in Context 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.