Dynamic Data creates Web pages (UI) that let users view and edit data in a database. Dynamic Data infers the appearance and the behavior of data fields in the UI from the database schema at run time. This mechanism, together with the availability of default page templates, field templates, entity templates, filter templates and many possibilities for customization, gives you a variety of design choices including the following:
The following illustration shows the architecture of Dynamic Data. Dynamic Data works with a data model (for example, the Entity Framework), which represents data in the data store. Dynamic Data infers the data schema from the data model and then uses templates to create UI for displaying and editing data. Metadata that is added to the data model specifies how Dynamic Data presents UI and how it manages data that is sent from the presentation layer.
The data model uses CLR types to represent the information that is in a database and how the items in the database are related to each other.
Dynamic Data supports the LINQ-to-SQL data model and the ADO.NET Entity Framework data model. When you create a Dynamic Data Web application, you can select the desired data model using the appropriate project template.
You register the data model that you want to use with Dynamic Data in the Web application's Global.asax file. After a data model is registered, Dynamic Data uses the model meta-data to automatically validate data fields, and lets you control appearance and behavior of data at the data layer level.
Scaffolding is a mechanism that enhances the existing ASP.NET page framework by dynamically displaying pages based on the data model. When the scaffolding mechanism is enabled in a Dynamic Data Web site, ASP.NET analyzes the data model and generates Web pages dynamically for each table. These auto-generated Web pages provide display, insert, delete, and edit capabilities for each table.
For more information, see ASP.NET Dynamic Data Infrastructure.
Page Templates
Dynamic Data uses page templates to provide a default view of data tables. These templates are ASP.NET Web pages and are configured to display data from any table that is available to Dynamic Data. Dynamic Data includes page templates for different views of data, such as listing a table (List view), displaying master/detail tables (Details view), editing data (Edit view). By default, when scaffolding is enabled, Dynamic Data uses only a List view page template.
When you create a Dynamic Data Web project, Visual Studio adds a DynamicData\PageTemplates folder to the project. This folder contains the default page templates.
You can modify the default page templates or you can configure Dynamic Data to use different page templates for different purposes.
For more information, see ASP.NET Dynamic Data Scaffolding and Page Templates Overview.
Entity Templates
Dynamic Data Entity templates provide a mechanism to customize the layout of data without requiring you to create a custom page. For example, the default entity templates show data in a two columns; a label for the field and the actual field value. You can create a custom entity template to show two data fields on each row, or any other layout. The default entity templates can be modified to change the appearance and behavior for the whole site. There are templates for display, edit, and insert operations. Entity templates are consumed by the Details.aspx, Insert.aspx and Update.aspx page templates, any custom pages. Entity templates use field templates to render the actual data. The entity templates are displayed on a page by using the DynamicEntity control. At run time, Dynamic Data replaces this control with the contents of the applicable entity template.
Entity templates map to a MetaColumn, while field templates map to a MetaColumn type. Entity templates display an entire entity (a row from a table), field templates display a single field in a table. Entity templates contain the label (or other HTML element to display the field name) and a field template for the each field displayed. A custom address entity template would map only to the address table, while field templates often map to many columns. The following illustration shows the default layout of an entity (row of data).
.png)
The following illustration shows the same data rendered with a custom entity template.
.png)
You generally create three custom entity templates for each table you wish to control the layout. The custom entity templates must be named after the entity representing the table. For example, using the default LINQ to SQL data model generated for the AdventureWorksLT database, entity templates for the Address table would be named Addresses.acx, Addresses_Edit.acx and Addresses_Insert.acx. Using the default ADO Entity Framework data model generated for the AdventureWorksLT database, entity templates for the Address table would be named Address.acx, Address_Edit.acx and Address_Insert.acx. These custom templates must be in the EntityTemplates directory. For more information, see >Walkthrough: Customizing Table layout using Entity Templates
For more information, see Working with Many-to-Many Data Relationships in Dynamic Data.
Field Templates
Dynamic Data uses a set of user controls, referred to as field templates, to render the UI for displaying and editing individual data fields. Dynamic Data determines the appropriate field template based on the data type of the data field that is being displayed or edited. Dynamic Data includes separate field templates for displaying and for editing data fields.
For example, for a DateTime data field, Dynamic Data uses the following field templates:
DateTime.ascx. This template displays DateTime data type as text (a string) and renders it as a Literal control.
DateTime_Edit.ascx. This template displays a TextBox control. If the field in the database cannot be null or if the data model has been customized to require an entry, this control also renders a RequiredFieldValidator control..
When you create a Dynamic Data Web project, Visual Studio adds a DynamicData\FieldTemplates folder to the project. This folder contains the default field templates.
You can modify the default field templates or create new ones in order to specify how individual data fields are rendered. For example, you can create field templates that render UI for displaying and editing telephone numbers. As another example, you can create field templates that render UI for using alternative ways (such as a slider) to let users specify numeric data.
Filter Templates
Dynamic Data uses a set of default user controls, referred to as filter templates, to render the UI for data filtering. Data filtering refers to the ability provided to the user to choose (filter) the table rows to be displayed based on a chosen column value. This enables the user to display only those rows that contain that particular column value.
Dynamic Data enables you to use page markup to create the UI for data filtering for a table column you identify. This approach is useful when you want to filter table rows for a column type for which Dynamic Data provides a default filter template. If a filter template does not exist for that column type, you can create a custom one and instruct Dynamic Data to use it for creating the UI. Finally, you can create the page markup to let Dynamic Data automatically generate the UI for any column type for which a filter template exists. Remember that by default only the UI for Boolean and foreign-key columns is created.
Dynamic Data performs data filtering as follows:
The filter template modifies the basic query for the data source control in the page to include the column value chosen by the user.
The data source control executes the modified query and returns the filtered data to the associated data-bound control, which displays the filtered data.
When you create a Dynamic Data Web project, Visual Studio adds a DynamicData\Filters folder to the project. This folder contains the default filter templates.
You can modify the default filter templates or create new ones in order to specify how data filtering is handled.