Back to Devexpress

IndicesAttribute Class

xpo-devexpress-dot-xpo-5421817c.md

latest4.2 KB
Original Source

IndicesAttribute Class

Specifies the properties that affect the creation of non-unique database indices.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
public sealed class IndicesAttribute :
    Attribute
vb
<AttributeUsage(AttributeTargets.Class, Inherited:=True)>
Public NotInheritable Class IndicesAttribute
    Inherits Attribute

Remarks

Apply this attribute to a persistent class to specify database indices to be created in the database table associated with the class. Unlike IndexedAttribute, IndicesAttribute allows you to specify several non-unique indices for the current table using a single attribute declaration. The following code snippet illustrates usage of both attributes.

csharp
[Indices("Name", "Name;Age", "Age;ChildCount")]
public class Person : XPObject {
    [Size(32)]
    public String Name {
        get { return fName; }
        set { SetPropertyValue(nameof(Name), ref fName, value); }
    }
    String fName;

    [Indexed(Unique = true), Size(64)]
    public String FullName {
        get { return fFullName; }
        set { SetPropertyValue(nameof(FullName), ref fFullName, value); }
    }
    String fFullName;

    public int Age {
        get { return fAge; }
        set { SetPropertyValue(nameof(Age), ref fAge, value); }
    }
    int fAge;

    public int ChildCount {
        get { return fChildCount; }
        set { SetPropertyValue(nameof(ChildCount), ref fChildCount, value); }
    }
    int fChildCount;

}
vb
<Indices("Name", "Name;Age", "Age;ChildCount")> _
Public Class [Person]
    Inherits XPObject
    <Size(32)> _
    Public Property Name() As String
        Get
            Return fName
        End Get
        Set(ByVal value as String)
            SetPropertyValue(NameOf(Name), fName, value)
        End Set
    End Property
    Private fName As String

    <Indexed(Unique := True), Size(64)> _
    Public Property FullName() As String
        Get
            Return fFullName
        End Get
        Set(ByVal value as String)
            SetPropertyValue(NameOf(FullName), fFullName, value)
        End Set
    End Property
    Private fFullName As String

    Public Property Age() As Integer
        Get
            Return fAge
        End Get
        Set(ByVal value as Integer)
            SetPropertyValue(NameOf(Age), fAge, value)
        End Set
    End Property
    Private fAge As Integer

    Public Property ChildCount() As Integer
        Get
            Return fChildCount
        End Get
        Set(ByVal value as Integer)
            SetPropertyValue(NameOf(ChildCount), fChildCount, value)
        End Set
    End Property
    Private fChildCount As Integer

End Class

With this code in place, the database table corresponding to Person will have four indices.

  1. A non-unique index over the Name column.
  2. A non-unique multi-column index over the Name and Age columns.
  3. A non-unique multi-column index over the Age and ChildCount columns.
  4. A unique index over the FullName column.

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.

Inheritance

Object Attribute IndicesAttribute

See Also

IndicesAttribute Members

Define Database Indexes

IndexedAttribute

AutoCreateOption

Built-In Attributes

DevExpress.Xpo Namespace