Skip to main content

Data Annotation Attributes

  • 11 minutes to read

You can apply attributes to a business class or its members to specify information necessary to generate your XAF application. The attributes can specify validation rules, how the data is displayed, set relationships between classes, and so on. This topic provides a list of built-in XAF attributes and information on where and how you can apply these attributes.

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 operation mode for Collection Sources created by associated property’s List Property Editors.

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.

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 affect Application Model construction.

ExpandObjectMembersAttribute

Specifies whether the target reference property is displayed via several Property Editors.

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.

HideInUIAttribute

Specifies whether the target property is initially visible in certain areas of application UI. For more information, refer to the following topic: HideInUI.

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.

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.

.NET Framework attributes

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

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 you specify false as the parameter, the target property is not available in the Model Editor and does not take part in UI construction. When applied to a business class, the attribute affects all class properties (the class itself remains available). XAF ignores this attribute when it calculates the IMemberInfo.IsVisible property. Alternatively, you can use [HideInUI(HideIn.All)] for the same purpose.

Properties are persisted, even with this attribute applied.

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 is a password or not. If it is, Property Editors and List Editors will display it as a string of 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 is 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. 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 is 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 autogenerated.

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 (for example, 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