inset
ASP.NET Extensions Previewed
Feb. 18, 2008

ASP.NET 3.5 Extensions, a set of add-ons to ASP.NET available in a preview release, could make it easier to build Web applications that access databases and could help Microsoft deal with the growing popularity of the Rails application framework. Other features of the ASP.NET Extensions include better support for Asynchronous JavaScript and XML (AJAX) and Silverlight. The additions illustrate the continue importance of ASP.NET to Microsoft's Web efforts and could help developers build more maintainable data-driven Web applications.

Extending Data Access

ASP.NET is an important part of Microsoft's developer platform: besides being a key part of the company's Web platform, it also serves as an important entry point into .NET development. For many developers, their first taste of .NET programming is in the context of ASP.NET.

Because Web applications are frequently used to provide browser-based access to corporate database and information systems, access to data is a critical piece of ASP.NET.

The ASP.NET Extensions, currently available in a free preview, include the following three components to help developers create data-driven Web applications:

  • ADO.NET Entity Framework, which allows developers to use a data modeling technique known as entity modeling
  • ADO.NET Data Services, which makes data from SQL Server and other databases available via simple Hypertext Transfer Protocol (HTTP) requests
  • ASP.NET Dynamic Data, which allows ASP.NET to generate pages automatically at run-time based on the contents of an underlying database.

Entity Framework

The ADO.NET Entity Framework helps developers access data in databases by introducing a layer that maps the details of the database schema into higher-level models, and by allowing developers to perform queries and other operations against the model rather than having to deal with the details of how the data was stored in the database.

Specifically, the Extensions will support Entity Data Modeling (EDM), a data modeling technique that allows developers and database professionals to describe the relationships between database tables and columns in a way that puts more emphasis on the logical entities that the data describe and less emphasis on the distinct tables used to represent the data in a relational database.

While designing a relational database, database professionals break information into separate tables to minimize duplication of information and prevent problems such as conflicting data. But this makes creating applications more complex because retrieving or updating all but the simplest of information requires the developer to use queries that join information from multiple tables.

The Entity Framework allows database professionals to build a higher-level conceptual model while maintaining the efficiency of the underlying relational model. For example, a sales tracking database might break data into three tables—one for sales people, one for orders, and one that identifies particular orders with particular sales people—along with numerous foreign keys and primary keys to connect the tables. With the Entity Framework, the data can be described in terms of a Sales Person entity that is associated with zero or more sales orders. The Entity Framework does the bookkeeping so that the developers can write queries that return all the orders for a given sales person without having to be aware of the details of the underlying tables.

The Entity Framework also introduces an extensibility mechanism that allows vendors such as IBM and Oracle to make their database products compatible with Language Integrated Query (LINQ). LINQ is a feature of Visual Studio 2008 and the .NET Framework 3.5 that lets developers express queries directly in programming languages such as Visual Basic and C#. LINQ already enabled access to SQL Server, XML, or the built-in data structures of the .NET Framework, but it did not support the other major database management systems.

RESTful Data Access

The ASP.NET Extensions include ADO.NET Data Services, code-named Astoria. Data Services make data from SQL Server, and potentially other databases, accessible via standard HTTP requests, using data formats common in Web programming. The result is a data access layer that follows the increasingly popular Representational State Transfer, or REST, architecture. (Systems that use these design patterns are often known as "RESTful" systems.)

Providing RESTful interfaces to existing databases makes them easier to access from Web services or from Web-based client applications such as AJAX, Flash, or Silverlight. (AJAX is an acronym used to describe a technique in which JavaScript in a Web page downloads small amounts of XML data in the background so that the entire page doesn't have to be refreshed.)

For example, Microsoft has used ADO.NET Data Services to expose its venerable Northwind sample database and make it available on the Internet. The complete list of customers in the database is available at astoria.sandbox.live.com/northwind/northwind.rse/Customers. Queries can be further refined by extending the URL. For example, all the orders for a customer with an ID of "ANTON" can be accessed via astoria.sandbox.live.com/northwind/northwind.rse/Customers('ANTON')/Orders. Queries can also be filtered and ordered through a similar mechanism.

To create an ADO.NET Data Service, the developer uses Visual Studio and the Entity Framework tools to create an ASP.NET Web application, define the logical entities that will be returned, and map those entities to the database tables.

By default, data is returned in JavaScript Object Notation (JSON) format, but the Entity Framework also supports the Atom Publishing Protocol. JSON is particularly well-suited for AJAX applications because the client piece of those applications is implemented in JavaScript. In addition to retrieving data, ADO.NET Data Services allows records to be updated through the usual HTTP operations: GET to retrieve data, PUT to replace a record, POST to add new records, and DELETE to remove a record.

Dynamic Data

Although ASP.NET and Visual Studio include a number of tools to help developers create Web applications that display data, the developer must still create each page individually, lay out the controls on the pages, and connect those controls to underlying data. With the ASP.NET Extensions, a new Dynamic Data feature enables ASP.NET to discover the underlying data and at runtime automatically generate Web pages to access that data. This allows developers to develop applications more quickly and have those applications be flexible in the face of changes to the underlying schema.

The developer creates a Dynamic Data site by using a new Visual Studio designer to choose the database tables to be displayed and the relationships between them. After selecting the tables, the developer needs only to enable Dynamic Data and the application is ready to run.

At runtime, Dynamic Data generates pages to display the data. The generated pages support several common features:

  • Laying out controls based on the type of data, such as choosing check boxes for Boolean values and drop-down lists for fields with a fixed set of possible values
  • Data paging, breaking large data sets into pages and adding navigation controls
  • Adding filtering controls at the top of the page, allowing users to view portions of the data
  • Editing support, allowing the user to click a link to edit data directly on the page instead of navigating to a separate page.

(For an illustration of a Dynamic Data application, see "ASP.NET Dynamic Data".)

Developers can customize a Dynamic Data application in several ways, including adding validation to enforce business rules. In addition, the appearance of the pages can be altered by editing a set of design templates and CSS style sheets.

Going After Rails

Because ASP.NET is an important component in Microsoft's application development platform, Microsoft wants it to remain a popular Web development platform in the face of new competition, such as Ruby on Rails, which combines the free Ruby programming language with the open source Rails application framework.

ASP.NET Extensions introduce an optional development architecture, known as model-view-controller (MVC), that is similar to Rails.

MVC is an architectural pattern that divides an application into three layers or components:

  • Model—the fundamental data the application manipulates; for a Web application, the model is typically stored in a database
  • View—a specific visualization of the model
  • Controller—responds to events from the user and makes changes to the model, thereby causing the views to be updated.

Separating the model from the view insulates the often rapidly changing user interface components from the more stable data. It also provides a framework for applications that offers multiple views that represent the same model. For example, a model containing spreadsheet data might have two views associated with it: one that displays the data in a grid and one that displays it as a chart.

MVC is not a new pattern—it was developed in the late 1970s by researchers at Xerox labs working on Smalltalk, an early object-oriented programming language—but it is an important part of the Rails framework, which is gaining popularity.

ASP.NET Extensions enable MVC-style applications, but require some changes in the way applications are created. For example, in most ASP.NET applications, changes made in the browser, such as text entered in an edit field, are sent to the server by posting them back to the same page. With MVC, the pages must be altered so that changes are sent to the Controller instead. In addition, to enforce MVC discipline, the ASP.NET Extensions can disable some features, such as the page life cycle, which enables the developer to write custom code that is executed during the various phases of a dynamic page, from creation through post back, and on to page disposal.

AJAX and Silverlight

In addition to the data features and MVC support, the ASP.NET Extensions include improvements in ASP.NET's support for AJAX development and Silverlight.

AJAX. ASP.NET Extensions introduce a new developer mechanism called "history points" to address a common user complaint about AJAX by making the browser history, along with the Back and Forward buttons, work as users expect. Millions of Web pages have trained users to expect that pressing the Back button in the browser takes them to the page they were previously viewing. But AJAX applications alter the appearance of the application without changing the URL. For example, with an AJAX-enabled real estate site, the user might enter search criteria and zoom in to a particular region, all of which cause the display to change without changing the URL of the page. Users might reasonably expect that pressing the Back button would take them back to their previous view of the map only to find that it takes them to the Web site they were viewing before they came to the real estate site.

The Extensions enable AJAX applications to programmatically specify history points, which create entries in the browser's history and then allow the Back and Forward buttons to navigate to those points. In addition, history points can be saved as browser bookmarks. The developer, however, must still write code to save and restore the state of the application when history points are created or navigated to.

Silverlight. A new Media Player control enables developers to incorporate Silverlight into a Web application. Silverlight is Microsoft's alternative to the Adobe Flash platform for Web video and Rich Internet Applications—Web applications that have features and functionality traditionally associated with desktop applications and can't easily be created with either HTML or AJAX, but which run locally in a Web browser through a browser plug-in. The new server-side control enables a developer to insert an audio or video element into the page and to customize the appearance of the playback controls in the browser.

Resources

The ASP.NET 3.5 Extensions preview can be downloaded from www.asp.net/downloads/3.5-extensions.