Skip to main content
All docs
V23.2
.NET 6.0+

ManyToManyAliasAttribute Class

Applied to properties. Binds parts of the many-to-many relationship defined with an intermediate object.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v23.2.dll

NuGet Package: DevExpress.Xpo

Declaration

[AttributeUsage(AttributeTargets.Property, Inherited = true)]
public sealed class ManyToManyAliasAttribute :
    Attribute

Remarks

The many-to-many relationship between two persistent objects with an intermediate object consists of two one-to-many relationships between “many” parts and the intermediate object. This technique allows you to create a many-to-many relationship in a legacy database or add custom properties to an intermediate object.

The following example demonstrates how to use this attribute:

using DevExpress.Xpo;
using System.Collections.Generic;
using System.ComponentModel;
// ...
// The Location class, which contains its name and information 
// about the departments at the location.
public class Location : XPObject {
    public Location(Session session) : base(session) { }
    public string Name {
        get { return fName; }
        set { SetPropertyValue(nameof(Name), ref fName, value); }
    }
    string fName;
    // Apply the Association attribute to mark the LocationDepartmentLinks property 
    // as the "many" end of the one-to-many association between Location and an intermediate object.
    [Association, Browsable(false)]
    public IList<LocationDepartmentLink> LocationDepartmentLinks {
        get {
            return GetList<LocationDepartmentLink>(nameof(LocationDepartmentLinks));
        }
    }
    // Apply the ManyToManyAlias attribute to mark the Departments property 
    // as the "many" end of the many-to-many association between Location and Department.
    [ManyToManyAlias(nameof(LocationDepartmentLinks), nameof(LocationDepartmentLink.LinkDepartment))]
    public IList<Department> Departments {
        get {
            return GetList<Department>(nameof(Departments));
        }
    }
}
// The Department class that contains its name 
// and references all the locations of the department's offices.
public class Department : XPObject {
    public Department(Session session) : base(session) { }
    public string Name {
        get { return fName; }
        set { SetPropertyValue(nameof(Name), ref fName, value); }
    }
    string fName;
    // Apply the Association attribute to mark the LocationDepartmentLinks property 
    // as the "many" end of the one-to-many association between Department and an intermediate object.
    [Association, Browsable(false)]
    public IList<LocationDepartmentLink> LocationDepartmentLinks {
        get {
            return GetList<LocationDepartmentLink>(nameof(LocationDepartmentLinks));
        }
    }
    // Apply the ManyToManyAlias attribute to mark the Locations property 
    // as the "many" end of the many-to-many association between Location and Department.
    [ManyToManyAlias(nameof(LocationDepartmentLinks), nameof(LocationDepartmentLink.LinkLocation))]
    public IList<Location> Locations {
        get {
            return GetList<Location>(nameof(Locations));
        }
    }
}
// The intermediate class that has links to Location and Department.
public class LocationDepartmentLink : XPObject {
    public LocationDepartmentLink(Session session) : base(session) { }
    private Location _LinkLocation;
    // Apply the Association attribute to mark the LinkLocation property 
    // as the "one" end of the one-to-many association between Location and an intermediate object.
    [Association]
    public Location LinkLocation {
        get { return _LinkLocation; }
        set { SetPropertyValue(nameof(LinkLocation), ref _LinkLocation, value); }
    }
    private Department _LinkDepartment;
    // Apply the Association attribute to mark the LinkDepartment property 
    // as the "one" end of the one-to-many association between Department and an intermediate object.
    [Association]
    public Department LinkDepartment {
        get { return _LinkDepartment; }
        set { SetPropertyValue(nameof(LinkDepartment), ref _LinkDepartment, value); }
    }
}

Inheritance

Object
Attribute
ManyToManyAliasAttribute
See Also