Databases Reference
In-Depth Information
NOTE
Enumeration columns represent properties with an actual enumerated .NET data type
(supported only by LINQ to SQL today) or integer properties that have been marked with
the EnumDataTypeAttribute (supported by both LINQ to SQL and Entity Framework).
As an example, consider the following enumerated type that could be used to track
status of Orders in the Northwind database:
public enum OrderStatus: byte
{
Draft = 0,
Submitted = 1,
PaymentProcessed = 2,
Fulfilled = 3
}
In the sample data model, it could be expressed as an integer property called
OrderStatus in the Order entity:
[EnumDataType(typeof(OrderStatus))]
public byte OrderStatus { get; set; }
By marking the OrderStatus property with the EnumDataTypeAttribute , you can make
Dynamic Data treat it as enumeration instead of an integer and use the Enumeration.ascx
field template, which displays OrderStatus field values as “ Draft ” and “ Submitted ,”
instead of “ 1 ” and “ 2 .”
Enumeration Edit
The Enumeration_Edit.ascx field template is used for enumeration columns in Edit and
Insert modes. It contains a DropDownList control, populated with enumerated items
converted to string, plus “[Not Set]” if the column allows null values. This field template
also includes a RequiredFieldValidator to enforce values for columns marked with the
RequiredAttribute and a DynamicValidator to enforce all other validation attributes
applied to this column.
NOTE
When converting enumeration values to string, the Enumeration field templates do not
automatically separate words concatenated to form a valid programmatic identifier. For
example, an enumerated value ReadOnly would be normally displayed as “read-only” in a
hand-coded web page. To make display names of the enumeration values more user-
friendly, you can modify the Enumeration field templates to implement appropriate logic
based either on the naming convention used to define the enumerated values, commonly
PascalCase in .NET programs. Alternatively, you can use metadata attributes, such as
DisplayAttribute , that can be applied to the enumerated values to specify the exact
display string. Chapter 11, “Building Dynamic Forms,” shows how to implement this.
 
Search WWH ::




Custom Search