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 |
---|---|
Action |
Converts a persistent class method into a Simple |
Appearance |
Applied to business classes and their properties. Declares a conditional appearance rule. |
Aggregated |
Applied to business class properties. Indicates that a property or field references other aggregated persistent objects. |
Calculated |
Applies to business class properties. Specifies an expression used to calculate the target property value. |
Calculated |
Applied to a business class. Allows you to dynamically configure a persistent alias for the target business class’ property. |
Captions |
Applied to Boolean business class properties. Specifies captions used to display the target property’s values. |
Code |
Applied to a validation rule. Specifies that the rule is intended for a particular business class and does not have a corresponding validation attribute. |
Collection |
Specifies the mode of operation for the Collection Sources created by List Property Editors representing the Collection |
Creatable |
Specifies whether a class will have a corresponding item in the New Action’s item list. |
Criteria |
Indicates that the target string property stores a filter criterion. |
Data |
Specifies the criteria expression used to filter source data for a reference, collection, or enumeration property. |
Data |
Specifies the Criteria |
Data |
Specifies the data source for a reference, collection, or enumeration property. |
Default |
Sets default options for a class. |
Default |
Applied to business classes. Sets a number of default options for the List Views that display objects of the target type. |
Detail |
Applied to business class properties. Specifies the Detail View layout options for a target property. |
Domain |
Specifies that a target class should be registered in the types info subsystem and should affect Application Model construction. |
Expand |
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. |
Field |
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 IModel |
File |
Applied to business classes that expose a property of the IFile |
File |
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. |
Friendly |
Specifies the property which is considered an analog of the GUID property, to allow use of more suitable values. |
Hide |
Specifies whether a business class property or enumeration value is initially visible in certain areas of application UI. |
Image |
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. |
Image |
Specifies the name of the image that is displayed for the target class’ objects or target enumeration value. |
Images |
Applied to Boolean business class properties. Specifies the names of the images used to display the target property’s values. |
Immediate |
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. |
Index |
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. |
Key |
Applied to properties of non-persistent classes. Specifies that a target property is a key property. |
List |
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. |
List |
Specifies the filters that an end-user will be able to apply to the List View that displays the target class’objects. |
Lookup |
Specifies the mode of the target business class property’s Lookup Property Editor. |
Model |
Specifies default settings that are considered when generating the Application Model node related to the target. |
Model |
Applied to Application Model node interfaces. Specifies a Nodes Generator for the current node. |
Navigation |
Specifies whether a class will have a corresponding item in the navigation control. |
Non |
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. |
Not |
Applied to a business class. Specifies the business class’ string property, which can hold the property values that were not cloned. |
Object |
Specifies a caption format for the target business class’ objects. |
Optimistic |
Applies to EF Core business class properties. Specifies concurrency options. |
Property |
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. |
Rule |
Represents a base class for validation system attributes. |
Rule |
Defines a validation rule that demands the target properties’ values combination be unique. |
Rule |
Defines a validation rule that demands an object of the target type satisfy a specified criterion. |
Rule |
Defines a validation rule that demands a true value for the target public non-persistent Boolean property. |
Rule |
Defines a validation rule demanding that an object should be referenced in objects of a specified type. |
Rule |
Defines a validation rule that demands a particular type object that satisfies a specified criterion, exist in the database. |
Rule |
Defines a validation rule that demands the target property’s value be within the specified value range (including the range’s end points). |
Rule |
Defines a validation rule that demands the target property match a specified pattern. |
Rule |
Defines a validation rule that demands that a property has a value. |
Rule |
Defines a validation rule that demands the target string type property’s value satisfy a specified condition. |
Rule |
Defines a validation rule that demands the target property’s value be unique. |
Rule |
Defines a validation rule that demands the target property’s value satisfy a specified condition. |
Search |
Specifies whether all properties of the target class can be used by the Full |
Search |
Specifies whether a property can be used by the Full |
Security |
Applied to business class properties together with the Browsable |
Tool |
Specifies a tooltip for a business object property in XAF Win |
View |
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. |
Visible |
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. |
Xaf |
Applied to business classes. Specifies the default property. |
Xaf |
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 |
---|---|
Specifies whether to make the target property visible in the Application Model. When you specify Properties are persisted, even with this attribute applied.
| |
Indicates that the current property is the default. This means the property is:
If this attribute is not applied to a business class’ property (including inherited properties), a property that contains a Alternatively, you can use the Xaf Specifically, this attribute’s value is assigned to the | |
Specifies a textual description of the target module (a descendant of the Module You can use the Module | |
Specifies a caption for a target business class or property. Alternatively, you can use the Xaf Specifically, this attribute’s value is assigned to the Caption property of the Application Model’s BOModel | <Class> or BOModel | <Class> | Own | |
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 IModel |
#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 |
---|---|
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 Association In XAF, objects from aggregated collections are retrieved by the 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 Property For details on how to set relationships with aggregated collections, refer to Relationships Between Persistent Objects in Code and UI. | |
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. | |
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. | |
Specifies a caption for the target enumeration value. Specifically, this attribute’s value is assigned to the IModel | |
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 Rule In XAF, the value passed as the attribute’s parameter is set as a maximum length for ASPx In fact, this attribute can be applied to any property type. This will influence the visibility of the corresponding List View column. If the Visible This attribute’s value is assigned to the IModel |