Back to Devexpress

DelayedAttribute Class

xpo-devexpress-dot-xpo-74977bbf.md

latest3.2 KB
Original Source

DelayedAttribute Class

Indicates that the property’s value should not be loaded when a persistent object is being loaded. The property will be loaded the first time it is accessed.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

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

Remarks

Use this attribute to improve performance when loading and updating properties that are rarely used, or contain large amounts of data. For more information, see Delayed Loading.

Example

The following example demonstrates how to delay the loading of the DelayedAttachment property and improve property value update performance, by enabling the DelayedAttribute.UpdateModifiedOnly property.

Note

This solution uses the XPDelayedProperty object explicitly and doesn’t raise property change notifications in all scenarios. You may need to explicitly call the Session.Save method after modifying the property value to save changes. Alternatively, implement the delayed property as shown in the Delayed Loading article.

csharp
using DevExpress.Xpo;

public class Customer : XPObject {
   // ...
   private XPDelayedProperty document = new XPDelayedProperty();
   // Improve update performance for the property's value
   // by passing true as the attribute's
   // updateModifiedOnly parameter.
   [Delayed(nameof(document), true)]
   public Byte[] DelayedAttachment {
      get { return (Byte[])document.Value; }
      set { document.Value = value; }
   }
}
vb
Imports DevExpress.Xpo

Public Class Customer
   Inherits XPObject
   ' ...
   Private document As XPDelayedProperty = New XPDelayedProperty()
   ' Improve update performance for the property's value
   ' by passing true as the attribute's
   ' updateModifiedOnly parameter.
   <Delayed(NameOf(document), True)> _
   Public Property DelayedAttachment() As Byte
       Get
           Return document.Value
       End Get
       Set
           document.Value = value
       End Set
   End Property
End Class

Inheritance

Object Attribute DelayedAttribute

See Also

DelayedAttribute Members

Built-In Attributes

DevExpress.Xpo Namespace