Skip to main content

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Data Annotation Attributes

  • 12 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 attributes that can be applied in an XAF application.

#Built-in XAF Attributes

Attribute Description
ActionAttribute Converts a persistent class method into a SimpleAction or PopupWindowShowAction.
AppearanceAttribute Applied to business classes and their properties. Declares a conditional appearance rule.
AggregatedAttribute Applied to business class properties. Indicates that a property or field references other aggregated persistent objects.
CalculatedAttribute Applies to business class properties. Specifies an expression used to calculate the target property value.
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 Indicates that the target string property stores a filter criterion.
DataSourceCriteriaAttribute Specifies the criteria expression used to filter source data for a reference, collection, or enumeration property.
DataSourceCriteriaPropertyAttribute Specifies the CriteriaOperator used to filter source data for a reference, collection, or enumeration property.
DataSourcePropertyAttribute Specifies the data source for a reference, collection, or enumeration property.
DefaultClassOptionsAttribute Sets default options for a class.
DefaultListViewOptionsAttribute Applied to business classes. Sets a number of default options for the List Views that 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 should affect Application Model construction.
ExpandObjectMembersAttribute Specifies whether the target reference property is displayed via several Property Editors representing the referenced object’s properties or via a single Lookup or Object Property Editor.
FieldSizeAttribute Specifies the maximum number of characters that users can type in Property Editors of the current member. You can also specify the current member’s IModelMember.Size property in the Model Editor. If the value passed to the FieldSize attribute is more than the Size property value, Property Editors ignore the attribute. In the XPO data model, use the SizeAttribute instead of FieldSizeAttribute.
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 Specifies a file type filter in the Open dialog’s “Files of type” box. You can apply this attribute to file data business classes, interfaces, and their properties in ASP.NET Core Blazor and Windows Forms applications.
FriendlyKeyPropertyAttribute Specifies the property which is considered an analog of the GUID property, to allow use of more suitable values.
HideInUIAttribute Specifies whether a business class property or enumeration value is initially visible in certain areas of application UI.
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 the images used to display the target property’s values.
ImmediatePostDataAttribute An attribute you can apply to business class properties. This attribute indicates that the Property Editor’s control value should be passed to the property of a bound object as soon as possible when a user changes the editor’s value.
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.
ListEditorAttribute Applied to a custom List Editor. Registers the List Editor in the application and specifies the object type for which the 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 the target business class 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 you use the Clone Object Module to clone objects.
NotClonedInfoAttribute Applied to a business class. Specifies the business class’ string property, which can hold the property values that were not cloned.
ObjectCaptionFormatAttribute Specifies a caption format for the target business class’ objects.
OptimisticLockAttribute Applies to EF Core business class properties. Specifies concurrency options.
PropertyEditorAttribute Applied to a custom Property Editor. Registers the Property Editor in the application and specifies the data type for which the Property Editor is intended.
RuleBaseAttribute Represents a base class for validation system attributes.
RuleCombinationOfPropertiesIsUniqueAttribute Defines a validation rule that demands the target properties’ values combination be unique.
RuleCriteriaAttribute Defines a validation rule that demands an object of the target type satisfy a specified criterion.
RuleFromBoolPropertyAttribute Defines a validation rule that demands a true value for the target public non-persistent Boolean property.
RuleIsReferencedAttribute Defines a validation rule demanding that an object should be referenced in objects of a specified type.
RuleObjectExistsAttribute Defines a validation rule that demands a particular type object that satisfies a specified criterion, exist in the database.
RuleRangeAttribute Defines a validation rule that demands the target property’s value be within the specified value range (including the range’s end points).
RuleRegularExpressionAttribute Defines a validation rule that demands the target property match a specified pattern.
RuleRequiredFieldAttribute Defines a validation rule that demands that a property has a value.
RuleStringComparisonAttribute Defines a validation rule that demands the target string type property’s value satisfy a specified condition.
RuleUniqueValueAttribute Defines a validation rule that demands the target property’s value be unique.
RuleValueComparisonAttribute Defines a validation rule that demands the target property’s value satisfy a specified condition.
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 a property can be used by the FullTextSearch Action, if it satisfies 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 Specifies a tooltip for a business object property in XAF WinForms, Blazor, and Web Forms applications.
ViewItemAttribute Applied to a custom View Item. Registers the View Item in the application and specifies the type of the Application Model‘s node used by the custom View Item.
VisibleInReportsAttribute When applied to business classes, specifies whether end-users can create reports on objects of the required class. When applied to a business class property, specifies if the target property is visible in the Report Designer.
XafDefaultPropertyAttribute Applied to business classes. Specifies the default property.
XafDisplayNameAttribute Specifies the display name of a business class, domain component, property, field or enumeration value.

#.NET Framework Attributes

You can use attributes 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

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.

BrowsableAttribute can be applied to enumeration values. When the attribute is set to false, the target value is not available in the editor item list.

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.

#XPO Attributes

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

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