Databases Reference
In-Depth Information
When you encounter a property that fits one of the types defined in the DataType
enumeration or perhaps a custom type unique to your business domain, it is a good idea
to go ahead and use the DataTypeAttribute to indicate that decision in the entity model.
In some cases, Dynamic Data will already have a built-in field template for this data type.
When it does not, you can easily implement a new field template with a matching name,
such as the PhoneNumber_Edit field template created in Chapter 3. By applying the
DataTypeAttribute during entity design, you are documenting the business purpose of
the property as well as some implied expectations of how values of this type will be
presented to the users.
By applying the DataTypeAttribute to a property, you are saying that its type is fundamen-
tal to the business domain. For instance, the PhoneNumber and EmailAddress types are
ubiquitous in contact management. However, saying that a particular type is fundamental
is a strong statement, and discovering new types is difficult as it requires a solid under-
standing of the business domain. It is a good idea to postpone defining a new data type
until you have at least two, ideally three or more, entity properties with a solid match for
the emerging pattern.
What if you already know that a particular property needs a different UI but do not have
any other examples that would justify definition of a new “data type?” In this situation, it
is better to use the UIHintAttribute and specify the name of a custom field template
instead of a data type. Going back to the example of Region property in the Employee
entity, you could revise the premature decision to call “State” a data type and use the
UIHint annotation instead:
[MetadataType(typeof(Metadata))]
partial class Employee
{
private abstract class Metadata
{
[UIHint(“State”)]
public object Region { get; set; }
}
}
Although the value specified in both DataType(“State”) and UIHint(“State”) annota-
tions is the same, the choice of attribute helps you to convey the design intent and distin-
guish between a distinct data type and a simple instance of a common data type that
needs special user interface.
 
Search WWH ::




Custom Search