Skip to main content
A newer version of this page is available. .

Data Annotation Attributes in Data Model

  • 11 minutes to read

In the eXpressApp Framework, some of the information used to generate a business application is specified in attributes. You can apply attributes to the Business Class (or its members) that specify validation rules, specify how the data is displayed, set relationships between classes, etc. This topic provides a list of built-in eXpressApp Framework attributes and information on where and how these attributes can be applied.

Attribute

Description

ActionAttribute

Converts a persistent class method into a SimpleAction or a PopupWindowShowAction.

AppearanceAttribute

Applied to business classes and their properties. Declares a conditional appearance rule.

AggregatedAttribute

Applied to business class properties. Functions exactly like the AggregatedAttribute from the DevExpress.ExpressApp.Xpo namespace.

CalculatedAttribute

Applied to business class properties. Functions exactly like the PersistentAliasAttribute.

CalculatedPersistentAliasAttribute

Applied to a business class. Allows you to dynamically configure a persistent alias for the target business class’ property.

CaptionsForBoolValuesAttribute

Applied to Boolean business class properties. Specifies captions used to display the target property’s values.

CodeRuleAttribute

Applied to a validation rule. Specifies that the rule is intended for a particular business class and does not have a corresponding validation attribute.

CollectionSourceModeAttribute

Specifies the mode of operation for the Collection Sources created by List Property Editors representing the CollectionSourceModeAttribute‘s target property.

CreatableItemAttribute

Specifies whether a class will have a corresponding item in the New Action’s item list.

CriteriaOptionsAttribute

Applied to a business class’ string property that stores a filter criterion for a business object collection.

DataSourceCriteriaAttribute

Specifies the criteria according to which a List View in an Object type property’s Lookup Property Editor is filtered.

DataSourceCriteriaPropertyAttribute

Specifies the business class property that provides a criteria for filtering the target property’s lookup data source.

DataSourcePropertyAttribute

Specifies the business class collection property that serves as the data source for the target reference business class property.

DefaultClassOptionsAttribute

Sets default options for a class.

DefaultListViewOptionsAttribute

Applied to business classes. Sets a number of the default options for the List Views that will display objects of the target type.

DelayedAttribute

Applied to reference properties of Entity Framework classes. Indicates that the property value should not be loaded when an entity object is being loaded. The property will be loaded the first time it is accessed.

DetailViewLayoutAttribute

Applied to business class properties. Specifies the Detail View layout options for a target property.

DomainComponentAttribute

Specifies that a target class should be registered in the types info subsystem and participate in generation of the Application Model.

ExpandObjectMembersAttribute

Specifies whether the target reference property is displayed via several Property Editors representing the referenced object’s properties using a single Lookup or Object Property Editor.

FieldSizeAttribute

Specifies the maximum number of characters that can be stored in a column, which is created to store the data of a property or field.

FileAttachmentAttribute

Applied to business classes that expose a property of the IFileData type. Activates Controllers that manage file attachments for the target business class. Specifies a property that stores a file attachment.

FileTypeFilterAttribute

Applied to file data business class properties. Specifies a file type filter that appears in the Open dialog’s “Files of type” box.

FriendlyKeyPropertyAttribute

Specifies a property that is considered an analog of the GUID property to allow the use of more suitable values.

ImageEditorAttribute

Applied to business class properties of the byte array type. Specifies that the target property persists an image. Attribute parameters specify settings to be used by Image Property Editors when displaying images persisted by the target property.

ImageNameAttribute

Specifies the name of the image that is displayed for the target class’ objects or target enumeration value.

ImagesForBoolValuesAttribute

Applied to Boolean business class properties. Specifies the names of images used to display a target property’s values.

ImmediatePostDataAttribute

Applied to Business Class properties. Indicates that the property value is updated immediately when changes occur in the current Property Editor’s bound control.

IndexAttribute

Specifies the target business class property’s order index that will be considered when generating layout items in a Detail View, and columns in a List View.

KeyAttribute

Applied to properties of non-persistent classes. Specifies that a target property is a key property. An example is provided in the How to: Display a Non-Persistent Object’s Detail View from the Navigation topic.

ListEditorAttribute

Applied to a custom List Editor. Registers the List Editor in an application and specifies the object type for which a List Editor is intended.

ListViewFilterAttribute

Specifies the filters that an end-user will be able to apply to the List View that displays the target class’ objects.

LookupEditorModeAttribute

Specifies the mode of a property’s Lookup Property Editor.

ModelDefaultAttribute

Specifies default settings that are considered when generating the Application Model node related to the target.

ModelNodesGeneratorAttribute

Applied to Application Model node interfaces. Specifies a Nodes Generator for the current node.

NavigationItemAttribute

Specifies whether a class will have a corresponding item in the navigation control.

NonCloneableAttribute

Applied to a business class’ property. Specifies that the target property’s value cannot be cloned when cloning objects using the Clone Object Module.

NotClonedInfoAttribute

Applied to a business class. Specifies a business class’ string property that can hold property values that were not cloned.

ObjectCaptionFormatAttribute

Applied to business classes. Specifies a caption format for the target business class’ objects.

PropertyEditorAttribute

Applied to a custom Property Editor. Registers the Property Editor in the application and specifies a data type for which the Property Editor is intended.

Attributes from the Validation module:

RuleBaseAttribute,

RuleCombinationOfPropertiesIsUniqueAttribute,

RuleCriteriaAttribute,

RuleFromBoolPropertyAttribute,

RuleIsReferencedAttribute,

RuleObjectExistsAttribute,

RuleRangeAttribute,

RuleRegularExpressionAttribute,

RuleRequiredFieldAttribute,

RuleStringComparisonAttribute,

RuleUniqueValueAttribute,

RuleValueComparisonAttribute.

Specify validation rules that must be satisfied by a class or property.

SearchClassOptionsAttribute

Specifies whether all properties of the target class can be used by the FullTextSearch Action if they satisfy the Filter Controller’s FilterController.FullTextSearchTargetPropertiesMode.

SearchMemberOptionsAttribute

Specifies whether all properties of the target class can be used by the FullTextSearch Action, if they satisfy the Filter Controller’s FilterController.FullTextSearchTargetPropertiesMode.

SecurityBrowsableAttribute

Applied to business class properties together with the Browsable(false) attribute. Unhides a hidden property in the Member Permissions configuration UI. The target property remains hidden in other places.

ToolTipAttribute

Applied to business class properties. Specifies the tooltip that is displayed for the target class’ objects.

ViewItemAttribute

Applied to a custom View Item. Registers a View Item in an application and specifies the type of the Application Model‘s node used by a custom View Item.

VisibleInDetailViewAttribute

Specifies whether or not the View Item that corresponds to the target property is visible in a Detail View.

VisibleInListViewAttribute

Specifies whether a column that corresponds to the target property is initially visible in a List View.

VisibleInLookupListViewAttribute

Specifies whether or not a column that corresponds to the target property is initially visible in a Lookup Property Editor’s List View.

VisibleInReportsAttribute

Specifies whether end-users can create reports on objects of the required class.

XafDefaultPropertyAttribute

Applied to business classes. Specifies the default property.

XafDisplayNameAttribute

Specifies the display name of a business class, property, field or enumeration value.

You can also use attributes (e.g., BrowsableAttribute, DefaultPropertyAttribute or DisplayNameAttribute) from the .NET Framework library.

The following table lists standard attributes from the System.ComponentModel namespace that are processed in a specific manner in XAF applications.

Attribute

Description

Notes

BrowsableAttribute

Specifies whether to make the target property visible in the Application Model. When false is passed as the parameter, the target property is not available in the Model Editor and do not take part in UI construction. When applied to a business class, the attribute affects all class properties (the class itself remains). This attribute is ignored when the IMemberInfo.IsVisible is calculated.

Properties are persisted, even when they are hidden using this attribute.

DefaultPropertyAttribute

Indicates that the current property is the default. This means the property is:

  • displayed in Lookup Property Editors;
  • takes part in form caption generation;
  • used in the FullTextSearch Action’s engine;
  • displayed in a List View’s first column.

If this attribute is not applied to a business class’ property (including inherited properties), a property that contains a Name as its part is considered the default (excluding inherited properties). If there are no such properties, the property specified by the FriendlyKeyPropertyAttribute is considered the default. If the FriendlyKeyPropertyAttribute is not applied to any property, it is considered that the business class does not have the default property. In this instance, usually the Object.ToString method is used to get textual object representation.

Alternatively, you can use the XafDefaultPropertyAttribute.

Specifically, this attribute’s value is assigned to the DefaultProperty attribute of Application Model’s Application | BOModel | Class node.

DescriptionAttribute

Specifies a textual description of the target module (a descendant of the ModuleBase class). This value, passed as the parameter, is set to the ModuleBase.Description property. Additionally, it specifies a description for a custom Application Model node/property (see Model Editor).

You can use the ModuleBase.Description property instead of this attribute.

DisplayNameAttribute

Specifies a caption for a target business class or property.

Alternatively, you can use the XafDisplayNameAttribute.

Specifically, this attribute’s value is assigned to the Caption property of the Application Model’s BOModel | <Class> or BOModel | <Class> | OwnMembers | <Member> node, respectively.

PasswordPropertyTextAttribute

Specifies whether the target property represents a password or not. If it does, Property Editors and List Editors will display it using characters such as asterisks.

This attribute’s value is assigned to the IModelCommonMemberViewItem.IsPassword property of Application Model’s BOModel | <Class> | OwnMembers | <Member> node.

The following table lists attributes from the DevExpress.Xpo namespace specifically used by XAF. The remaining built-in XPO attributes are processed only by XPO.

Attribute

Description

Notes

AggregatedAttribute

Indicates that a property or field references other aggregated persistent objects. When this attribute is applied to a collection property, it must be accompanied by the AssociationAttribute.

In XAF, objects from aggregated collections are retrieved by the XPNestedObjectSpace (see BaseObjectSpace). If an aggregated collection represents a part of the One-To-Many relationship, the Link and Unlink Actions are not available, but the New Action is added to populate the collection.

Aggregated objects are meant to be created and managed only in the context of a master object, since they are considered a part of it. So, when XAF generates the default Detail View for an aggregated child object, a Property Editor corresponding to the associated master object is not included in the layout. To override this behavior, first, invoke the Model Editor for the required Views | Detail View node’s Items child node. Add a PropertyEditor child node using the context menu for the property that represents the owning class. Second, add the newly declared Property Editor to the Detail View’s layout (see View Items Layout Customization).

For details on how to set relationships with aggregated collections, refer to Relationships Between Persistent Objects in Code and UI.

KeyAttribute

Indicates that a property or a field is a key. Key properties (fields) can be read-only in XAF applications.

Key property values are used to correctly identify and distinguish between different instances of a business class. Usually, key properties are read-only and auto-generated.

MemberDesignTimeVisibilityAttribute

Specifies whether to make the target business class or member visible in the Application Model or not. If you pass false as the attribute’s parameter, you will not see the target class/member in the Model Editor or in the UI.

Properties are persisted, even when they are hidden using this attribute.

DisplayNameAttribute

Specifies a caption for the target enumeration value.

Specifically, this attribute’s value is assigned to the IModelLocalizationItem.Value property of Application Model’s Localization | Enums | Enum | EnumerationValue node.

SizeAttribute

Specifies the maximum number of characters that can be stored in a column created to store the data of the target string type property. If this attribute is not applied, a string property can be set to a value consisting of a maximum of 100 characters.

Note that this attribute only specifies the database column size. The attribute does not prevent users from entering more than the specified number of characters using Property Editors. For instance, suppose you have a string property decorated with the Size attribute that specifies that the corresponding database column’s size must be 10. If a custom Property Editor used to visualize the property allows users to enter more characters, it is perfectly valid for them to do so. In this instance, a SQL exception will be raised when trying to save an object. To ensure that users will not be able to enter and save more than a fixed maximum number of characters, use the Validation Module. For example, you can decorate a business class with RuleCriteriaAttribute, and use the Len function operator to enforce the maximum length for a string property.

In XAF, the value passed as the attribute’s parameter is set as a maximum length for ASPxStringPropertyEditor and Windows Forms RichTextPropertyEditor.

In fact, this attribute can be applied to any property type. This will influence the visibility of the corresponding List View column. If the VisibleInListViewAttribute and DelayedAttribute are not applied to a target property and the SizeAttribute‘s parameter passes a value that is more than 255 (e.g., SizeAttribute.Unlimited), the corresponding column is set invisible by default.

This attribute’s value is assigned to the IModelMember.Size property of the Application Model’s BOModel | <Class> | OwnMembers | <Member> node.

See Also