Databases Reference
In-Depth Information
Dynamic Data tries to find the most specific template that matches the field based on the
column type and control mode. If such a field template does not exist, Dynamic Data will
gradually relax the matching rules until it finds the best possible match among the field
templates in the project.
Data Annotations
Consider the RequiredDate column of the Order table used in Listing 3.3 earlier in this
chapter. If the developer specifies the exact template name by applying the
UIHintAttribute
as shown in Listing 3.14, Dynamic Data first checks to see if a template
with the specified name,
MyDate.ascx
, exists. If this template does not exist, Dynamic
Data then checks if a
DataTypeAttribute
is applied to the column and tries using the
specified
DataType
value as the template name. In this example, it checks to see if a field
template called
Date.ascx
exists.
LISTING 3.14
Data Annotations That Affect Field Template Lookup
using System.ComponentModel.DataAnnotations;
namespace DataModel
{
[MetadataType(typeof(Order.Metadata))]
partial class Order
{
public class Metadata
{
[UIHint(“MyDate”)]
[DataType(DataType.Date)]
public object RequiredDate;
}
}
}
Type Names
If the column has no data annotation attributes, Dynamic Data then tries to find a match-
ing template based on the name of its type. First, it looks for a template whose name
matches the full name of the type, including the namespace where the type is defined. In
the example of
RequiredDate
, when looking for a template for a column of
DateTime
type,
it checks to see if a template called
System.DateTime.ascx
exists. If not, Dynamic Data
then tries the short type name, without the namespace, and finally chooses the template
called
DateTime.ascx
provided by Dynamic Data out of the box
.