In this age of doing more with less, government software developers are constantly having to shrink the “time-to-release” and in some instances even compromise quality. Development teams have to content with picking up new skills/technologies, while maintaining older systems and dealing with the growing complexity of requirements. For this and other reasons, productivity has become a key requirement for any team charted with creating solutions with little time, little money and At The Speed Of Web. Enters ADO.NET Dynamic Data! (Herein Dynamic Data).

Dynamic Data is an great innovation with the potential to squeeze a great deal of development productivity when building data-driven websites. It provides some basic features:

  • Scafolding: Templated data generation at the page or field level.
  • Model: Custom behavior and validations via metadata specification.
  • Customization: based on the Dynamic Data templating system.

Scaffolding

  • The highest level scenario that Dynamic Data enables is what is called “scaffolding”. What this provides for you is a pre-generated set of pages and user controls that are used to template a full-blown web application that provides full CRUD operations against a data model you specify.
  • The underlying data model can be any arbitrary data source. It is important to note that Dynamic Data isn’t coupled to a relational database, it is a templating/scaffolding framework for data-driven web applications. “Data” != “Database”.
  • Two providers are available out-of-the-box: Entity Framework and LINQ 2 SQL.
  • The scaffolding behavior is fully templated, which means that you can modify and extend any of the provided templates to best suite your needs. We’ll cover more about customization of templates below.
  • The templates provided with your Dynamic Data application are all AJAX-enabled, so you get a very rich user-experience out of the box.
  • Aside from the templating system, the entire Dynamic Data framework is very extensible and allows you to modify logic at almost every step, allowing a great level of flexibility.

Model Metadata

  • The Dynamic Data framework is able to take full advantage of a set of common attributes that you can add to your underlying data model. By adding custom metadata to your model, the scaffolding system can react to your changes and render its page/field templates differently.
  • There are seven metadata attributes that you can use to salt your model classes to add additional semantics that Dynamic Data can understand.
  • The data type attribute allows you to associate a model property with a custom data type, adding richer semantic value to it, than can translate into a custom field template being used, a custom display format, etc.
  • The display column attribute allows you to specify which column in your model class represents the display name of the class. It also allows you to specify which column should be the default sort column.
  • The display format attribute allows you to specify a format string that will be applied to the column value when displayed. You can specify whether the format should be applied in edit mode as well.
  • The display name allows you to give a table in your model a different name that will override the class name.
  • The scaffold attribute allows you to specify whether a table should or scaffolded or not.
  • The UI hint attribute allows you to override the default field template association with a property (based on its type).

Validation

  • The Dynamic Data framework is able to take full advantage of a set of common attributes that you can add to your underlying data model. By adding custom validation to your model, the scaffolding system can react to your changes and render its page/field templates differently.
  • There are four validation attributes that you can use to salt your model classes that Dynamic Data can understand.
  • The range attribute allows you to specify a range of allowable values for a property on a model class.
  • The regular expression attribute allows you to apply a regex pattern that the value of a model class’s property must match.
  • The required attribute allows you to mark a model class’s property as requiring a value.
  • The string length attribute allows you to constrain a string property as only being able to be a certain length.
  • In addition to being able to apply the four validation attributes to your model classes, you can apply arbitrary validation logic to a model class by leveraging partial methods. If you’re using LINQ To SQL or the Entity Framework, both will have generated a set of partial methods for each of your model classes that represent a hook for you to perform logic when a property’s value is being changed. This allows you to validate the property value and throw an exception (ValidationException) if the property value isn’t good.
  • The DynamicValidator control will consume any ValidationExceptions you throw within your model classes and display them in a ValidationSummary control.

Customization

  • The scaffolded web application that is provided by Dynamic Data is fully customizable through the use of its templating system.
  • The provided page templates can be completely modified, including the HTML, CSS, and server-controls. Because the templates are leveraged for each of the pages in the scaffolded site, if you make a change in one of the templates it will reflect through your entire app.
  • In addition to modifying the existing page templates, you can create custom pages that are used for specific tables in your model, allowing you to have fully unique templates for specific model classes.
  • Aside from performing page-level templating, you can make field-level modifications to your Dynamic Data application. This allows you to change the way individual fields are rendered based on their data type.
  • You can create new field templates that include either a read-only, edit view, insert view, or all of the above. All field templates inherit from FieldTemplateUserControl which provides a lot of base functionality, including access to the metadata for the column the user control represents.

Summary

All the underlying functionality provided by Dynamic Data enables the creation of fully functional, data-driven web applications; enhancing quality without compromising flexibility to make changes to both the UI and the model. For government dev teams, of any size, interested in focusing their energy on the key requirements and less time on the pluming ADO.NET Dynamic Data is something to consider.

References

for a tour of how ASP.NET Dynamic Data is integrated into Visual Studio check ScottGu’s blog entry on the subject. There is also a webcast by Rachel Appel here.

 

Joel Reyes

Technorati Tags: