Databases Reference
In-Depth Information
The
AutoGenerateField
property affects both single-item forms and list pages generated
by Dynamic Data. For list pages, you can also set the
AutoGenerateFilter
property in the
DisplayAttribute
to explicitly specify whether the
QueryableFilterRepeater
control will
generate a
DynamicFilter
control instance for this property.
NOTE
DisplayAttribute
is the main data annotation attribute you use to control the layout
and appearance of dynamic forms in version 4.0 or later of ASP.NET Dynamic Data. It
was designed to replace several other data annotation attributes, including
DisplayNameAttribute
,
DescriptionAttribute
,
ScaffoldColumnAttribute
, and
ReadOnlyAttribute
, that were used by the original version of Dynamic Data released
with ASP.NET 3.5 SP1. These attributes are still supported; however, with rare excep-
tions, you should consider using the
DisplayAttribute
as it combines multiple anno-
tations into a single, easy-to-discover attribute class.
By default, properties appear on a dynamic form in the order they are defined in the
entity model. If this does not match what you need,
ideally
you want to change the order
of properties in the entity model. This is easy to do if you are using the code-first
approach with Entity Framework. If you are using the model-first approach, you can do
this by editing the raw XML in the EDMX file in a text editor. If you are using the data-
base-first approach, you need to reorder columns in the database table and regenerate the
model. Controlling order of data entry controls on dynamic forms by reordering proper-
ties in the entity model is ideal because it eliminates ambiguity and keeps the model
simple. After all, if you had a custom form laid out with an HTML table, you would want
to move a particular row to its new location, keeping the order of elements in the markup
in sync with their appearance on screen. Same idea applies to controlling order of controls
in dynamically generated forms.
However, in the real world, you have to deal with the less than ideal tools and larger than
ideal databases. When changing the order of properties in the entity model becomes
impractical, you can specify it explicitly by setting the
Order
property of the
DisplayAttribute
. Here is an example that shows how to do this for the
FirstName
and
LastName
properties of the Employee entity:
[MetadataType(typeof(Metadata))]
partial class Employee
{
private abstract class Metadata
{
[Display(Order = 110)]
public object FirstName { get; set; }
[Display(Order = 120)]
public object LastName { get; set; }
}
}