Databases Reference
In-Depth Information
NOTE
A single display column is often insufficient to provide a meaningful text that identifies
rows of a non-trivial entity. Consider a Customer entity where instead of the combined
ContactName as we have in the Northwind sample database, you have separate proper-
ties called FirstName , LastName , and MiddleName . You would probably want to use a
combination of two or three of these properties as a display value.
A straightforward solution to this problem would be to define a custom property called
FullName , as just shown and specify it as the display column for the entity class by
applying the DisplayColumnAttribute :
[DisplayColumn(“FullName”)]
partial class Customer
{
public string FullName
{
get { return LastName + “, “ + FirstName + “ “ + MiddleName; }
}
}
Unfortunately, this approach does not work out of the box due to a limitation of the
Entity Framework data model provider in Dynamic Data. As a workaround, you can over-
ride the ToString method in your entity class to return the required display string.
partial class Customer
{
public override ToString()
{
return LastName + “, “ + FirstName + “ “ + MiddleName;
}
}
When it comes to populating drop-down lists and generating links to pages, the value
returned by the ToString method takes precedence over the column specified in the
DisplayColumnAttribute and returned by the DisplayColumn property of the
MetaTable class.
Chapter 13, “Building Dynamic List Pages,” discusses the Dynamic Data provider
model in detail and offers a better solution for this problem.
public AttributeCollection Attributes { get; }
All attributes of the entity can be also accessed through the Attributes property of the
MetaTable class. This includes the built-in attributes from the System.ComponentModel and
System.ComponentModel.DataAnnotations namespaces discussed in this topic as well as
any custom attributes you might have created in your application.
 
Search WWH ::




Custom Search