Back to Devexpress

AssociationAttribute Class

xpo-devexpress-dot-xpo-a458aba9.md

latest3.5 KB
Original Source

AssociationAttribute Class

Identifies the end of an association that is involved in an object relationship.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

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

Remarks

Apply this attribute to both properties at the ends of the association, specifying an object relationship.

Example

In the following sample code, the Location class might contain several Departments and each Department can in turn span several Locations.

csharp
using DevExpress.Xpo;
// ...
public class Location : XPObject {
    public string Name {
        get { return fName; }
        set { SetPropertyValue(nameof(Name), ref fName, value); }
    }
    string fName;

    [Association("Locations-Departments")]
    public XPCollection<Department> Departments { 
        get { return GetCollection<Department>(nameof(Departments)); }
    }
}
public class Department : XPObject {
    public string Name {
        get { return fName; }
        set { SetPropertyValue(nameof(Name), ref fName, value); }
    }
    string fName;

    [Association("Locations-Departments")]
    public XPCollection<Location> Locations { 
        get { return GetCollection<Location>(nameof(Locations)); } 
    }
}
vb
Imports DevExpress.Xpo
' ...
Public Class Location
    Inherits XPObject
    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

    <Association("Locations-Departments")> _
    Public ReadOnly Property Departments() As XPCollection(Of Department)
        Get
            Return GetCollection(Of Department)(NameOf(Departments))
        End Get
    End Property
End Class
Public Class Department
    Inherits XPObject
    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

    <Association("Locations-Departments")> _
    Public ReadOnly Property Locations() As XPCollection(Of Location)
        Get
            Return GetCollection(Of Location)(NameOf(Locations))
        End Get
    End Property
End Class

Inheritance

Object Attribute AssociationAttribute

See Also

AssociationAttribute Members

Relationships Between Objects

Built-In Attributes

DevExpress.Xpo Namespace