One-to-Many and Many-to-Many Relationships

Important

Domain Component (DC) interfaces are abstractions above eXpress Persistent Objects (XPO) classes. Notwithstanding its benefits, this abstraction imposes certain technical limitations. DC is only suitable for certain usage scenarios. Mobile and SPA User Interfaces are not supported for DC. DC is in maintenance mode and we do not recommend its use in new software projects.

With Domain Components, you do not need to use the Association attribute to define one-to-many and many-to-many relationships. All you need to do is declare properties of the correct types. The following code snippet demonstrates a one-to-many relationship between the IOrder and IOrderItem Domain Components.

[DomainComponent]
public interface IOrder {
    IList<IOrderItem> Items { get; }
}
[DomainComponent]
public interface IOrderItem {
    IOrder Order { get; set; }
}

The following code snippet demonstrates a many-to-many relationship between the IEmployee and ITask Domain Components.

[DomainComponent]
public interface IEmployee {
    IList<ITask> Tasks { get; }
}
[DomainComponent]
public interface ITask {
    IList<IEmployee> Employees { get; }
}
Tip

You can declare only one side of the relationship (e.g,, IEmployee.Tasks collection property in the code above). The second collection will be declared automatically in the generated XPO class, however it will be inaccessible from your code and invisible in UI.

If a Domain Component exposes several properties of the same type, and a relationship cannot be resolved explicitly, you can use the BackReferenceProperty attribute to specify the correct property. The following code snippet illustrates this.

[DomainComponent]
public interface IAccount {
    [BackReferenceProperty("AccountOne")]
    IList<IContact> ContactA { get; }
    [BackReferenceProperty("AccountTwo")]
    IList<IContact> ContactB { get; }
    IList<IContact> ContactC { get; }
}
[DomainComponent]
public interface IContact {
    string Name { get; set; }
    IAccount AccountOne { get; set; }
    IAccount AccountTwo { get; set; }
    IAccount AccountThree { get; set; }
}