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

Delayed Loading

  • 2 minutes to read

By default, all properties and fields are restored from a data store when a persistent object is loaded. To improve application performance, the delayed loading feature can be used. This feature allows loading of particular properties, which are rarely used or contain large amounts of data (e.g. images, large memos, or binary data), to be delayed. A property marked for delayed loading will be loaded the first time it is accessed.

To delay the loading of a property, apply the DelayedAttribute to it, and use the GetDelayedPropertyValue and SetDelayedPropertyValue methods in this property getter and setter.


[Delayed]
public Byte[] BigPicture {
    get { return GetDelayedPropertyValue<Byte[]>("BigPicture"); }
    set { SetDelayedPropertyValue<Byte[]>("BigPicture", value); }
}

For your convenience, the methods in a delayed property’s getter and setter shown above automatically create an XPDelayedProperty behind the scenes, to store the property’s value.

To further improve performance when using a delayed property, you can ensure that it saves only modified values to a data store. This allows you to avoid sending the delayed property’s values for update once a persistent object is saved, which is done by default for all the object’s properties (including delayed properties). To enable saving only modified property values (which is disabled by default), pass true as the DelayedAttribute.UpdateModifiedOnly parameter, as shown below:


[Delayed(true)]
public Byte[] BigPicture {
//...

Delayed properties can be grouped. All properties in a group are loaded simultaneously when any property is accessed for the first time. To associate a property with a group, assign the group’s name via the DelayedAttribute.GroupName parameter. This does not affect properties whose type is a persistent class - delayed referenced objects are always loaded separately.

Note

  • Use the DelayedAttribute only with properties. Persistent members declared as fields do not support delayed loading.

  • You do not need to use the DelayedAttribute with XPCollections, because they always employ delayed loading. XPCollections are populated on demand.

Task-Based Help