xpo-devexpress-dot-xpo-931adede.md
Indicates that a property or field affects index creation.
Namespace : DevExpress.Xpo
Assembly : DevExpress.Xpo.v25.2.dll
NuGet Package : DevExpress.Xpo
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
public sealed class IndexedAttribute :
Attribute
<AttributeUsage(AttributeTargets.Property Or AttributeTargets.Field, Inherited:=True)>
Public NotInheritable Class IndexedAttribute
Inherits Attribute
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;
}
Public Class User
Inherits XPObject
<Indexed(Unique:=True)>
Public Property UserId As Integer
Get
Return fUserId
End Get
Set(ByVal value As Integer)
SetPropertyValue(NameOf(UserId), fUserId, value)
End Set
End Property
Private fUserId As Integer
Public Property UserName As String
Get
Return fUserName
End Get
Set(ByVal value As String)
SetPropertyValue(NameOf(UserName), fUserName, value)
End Set
End Property
Private fUserName As String
End Class
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.
Object Attribute IndexedAttribute
See Also