Databases Reference
In-Depth Information
Type Aliases
Dynamic Data allows template names to use special aliases instead of actual type names
for two built-in .NET types,
Int32
and
String
. When looking for a field template for a
column of type
String
, Dynamic Data considers the template called
Text.ascx
to be a
match. In the Northwind data model, this means that the
Text.ascx
template will be used
for the ProductName column of the Product table. Likewise, when looking for a template
for an
Int32
column, Dynamic Data considers
Integer.ascx
to be a match as well. Table
3.1 shows the built-in type aliases at a glance.
TABLE 3.1
Type Name Aliases
Type Name
Alias
Int32
Integer
String
Text
Type aliases are considered less specific than the type names, and type
names
take prece-
dence over
aliases
during template lookup. For example, if the Dynamic Data project
contains templates called
Int32.ascx
and
Integer.ascx
, only the one called
Int32.ascx
will be used for an integer column.
Type Fallback
If there is no matching field template for a particular data type, Dynamic Data uses
fall-
back logic
to find a template for a more generic type that could be used instead. Consider
the UnitsInStock column of the Product entity, which is of type
Int16
. When looking for
a field template for this column, Dynamic Data first checks to see if a template called
Int16.ascx
exists. Because there is no template with this name, it uses the fallback rules
shown in Table 3.2 to determine the fallback type,
Int32
, and tries to find a matching
template for that type.
TABLE 3.2
Type Fallback Rules
Data Type
Fallback Type
Double, Float
Decimal
Byte, Int16, Int64
Int32
Char, Decimal, DateTime, DateTimeOffset, Guid Int32, TimeSpan
String
Both type names and aliases are used during template lookup for the fallback type, just as
they were used for the original type. For the UnitsInStock column, this means that
Dynamic Data will then try
System.Int32.ascx
,
Int32.ascx
, and
Integer.ascx
. Because
none of these field templates exist in the default Dynamic Data project, it falls back to the
next type—
String
and tries
System.String.ascx
,
String.ascx
, and finally choosing
Text.ascx
.