IndexedAttribute Class
Indicates that a property or field affects index creation.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v24.2.dll
Declaration
Remarks
The IndexedAttribute
attribute indicates that a table (or another data store) should have an index for the column(s). An index allows a database to find data in a table without scanning the entire table. Indexes can be created for a single property (column) or combination of properties (columns). For more information on multi-column (compound) indexes, refer to the IndexedAttribute.AdditionalFields property description.
Note
XPO does not support tables with multi-column (compound) keys or indexes in ASE databases. To avoid exceptions when connecting to ASE databases containing these tables, use one-column keys or indexes.
For instance, you can apply the IndexedAttribute
attribute to a persistent property to make it unique (see the example below):
public class User : XPObject {
[Indexed(Unique = true)]
public int UserId {
get { return fUserId; }
set { SetPropertyValue(nameof(UserId), ref fUserId, value); }
}
int fUserId;
public string UserName {
get { return fUserName; }
set { SetPropertyValue(nameof(UserName), ref fUserName, value); }
}
string fUserName;
}
This index ensures that the UserId
value is unique for all database records (both existing and deleted objects). To avoid a unique constraint violation when a deleted and existing object have the same UserId
value, include the GCRecord
field in the index. For more information, refer to the following help section: Include XPO’s Service Columns into Indexes to Enable Unique Value Constraints.
To define several non-unique database indices, use IndicesAttribute.