Databases Reference
In-Depth Information
to include human-readable property names instead of their internal, PascalCased, values.
Listing 10.7 shows an example of how the display names can be specified by applying the
DisplayAttribute to entity properties.
LISTING 10.7 Customer Entity Data Annotations
using System.ComponentModel.DataAnnotations;
namespace DataModel
{
[MetadataType(typeof(Customer.Metadata))]
partial class Customer
{
public abstract class Metadata
{
[Display(Name = “Name”)]
public object ContactName { get; set; }
[Display(Name = “ID”)]
public object CustomerID { get; set; }
}
}
}
With the current implementations, the display names specified with data annotations
match the names hard-coded in the template markup. However, in real-world applica-
tions, it is common for the terminology to change as developers continue learning the
business domain. When a display name for a particular property changes, it needs to be
updated in all places where it is hard-coded. Dynamic entity templates solve this problem
by generating the labels from column metadata, so the display names can be specified
only once in the data model. However, using the same approach in custom entity
templates is problematic because the built-in Label control cannot be directly associated
with a particular MetaColumn .
This problem can be solved by a simple control, UnleashedLabel , included in the sample
Unleashed.DynamicData project accompanying this topic. This control inherits from the
Label class and, similar to DynamicControl and DynamicHyperLink , defines a property
called DataField to hold the name of the entity property whose display name needs to be
rendered by the template. You can specify the DataField in template markup and the
control would find the corresponding MetaColumn and render its DisplayName at runtime.
So instead of hard-coding the customer name like this:
<label>Name</label>
you can implement it in the template markup as shown here:
<unl:UnleashedLabel runat=”server” DataField=”ContactName”/>
 
Search WWH ::




Custom Search