Skip to main content
A newer version of this page is available. .

How to: Create an Aggregated Object

  • 2 minutes to read

An aggregated object is considered a part of the owning object and cannot exist separately. When the owner is deleted, aggregated objects must be deleted as well. XPO can handle aggregated object deletion automatically. To do this, use the AggregatedAttribute to specify links to aggregated objects. In the following code example, the DefaultAddress and Addresses properties are considered to be a natural part of the Person objects, so we mark these properties as aggregated.


public class Address : XPObject {
    // For brevity, we omitted the declaration of constructors
    // and fields corresponding to persistent properties.
    // ...
    public string City;
    public string Street;

    [Association("PersonAddresses")]
    public Person Owner;
}

public class Person : XPObject {
    // For brevity, we omitted the declaration of constructors
    // and fields corresponding to persistent properties.
    // ...
    public override void AfterConstruction() {
        base.AfterConstruction();
        DefaultAddress = new Address(Session);
    }

    [Aggregated]
    public Address DefaultAddress;

    [Aggregated, Association("PersonAddresses")]
    public XPCollection<Address> Addresses {
        get { return GetCollection<Address>("Addresses"); }
    }
}

Note

We did not mark the Address class as aggregated, because the aggregation is an attribute of an object association and is not a class in itself.

See Also