How to: Affect Auto-Generated Columns and Edit Fields at the Data Model Level
- 2 minutes to read
You can extend a data model to customize the way grid columns and edit fields look and operate in the wizard-generated views. You can, for example, apply custom format strings, validation rules, or editor masks in the data model using DevExpress FluentAPI or property attributes.
Extend Data Model with the FluentAPI
A wizard-generated application contains a *MetadataProvider class where display names for properties are assigned.
public class TestDbContextMetadataProvider {
public static void BuildMetadata(MetadataBuilder<TestEntity> builder) {
builder.DisplayName(TestDbContextResources.TestEntity);
builder.Property(x => x.ID).DisplayName(TestDbContextResources.TestEntity_ID);
builder.Property(x => x.Name).DisplayName(TestDbContextResources.TestEntity_Name);
builder.Property(x => x.Value).DisplayName(TestDbContextResources.TestEntity_Value);
}
//...
}
You can extend the *MetadataProvider class to apply custom format strings, validation rules, or editor masks.
The code sample below illustrates how to apply a currency mask to the Value property.
public static void BuildMetadata(MetadataBuilder<TestEntity> builder) {
//...
builder.Property(x => x.Value).NumericMask(mask: "c", useMaskAsDisplayFormat: true);
}
Extend Data Model with Data Annotation Attributes
You can apply the Data Annotation Attributes to extend the data model.
The code sample below illustrates how to apply a currency mask to the Value property.