Skip to main content
All docs
V24.2
.NET 8.0+

XAF0011: Implement the delayed property correctly

  • 2 minutes to read

Severity: Error

XPO requires that every delayed property is decorated with the DevExpress.Xpo.DelayedAttribute attribute and meets one of these requirements:

  • (Recommended) A delayed property must use the GetDelayedPropertyValue<T>() and SetDelayedPropertyValue<T>() methods in its getter and setter, respectively.

or

Refer to the following article for details: Delayed Loading

This diagnostic works only for business classes derived from PersistentBase.

Examples

Invalid Code

using DevExpress.Xpo;

namespace TestApplication.Module.BusinessObjects {
    public class TestClass : XPObject { 
        public TestClass(Session session): base(session) {}

        // The delayed property is not implemented correctly.
        // [Delayed(true)] // Error
        // public int TestProperty1 { get; set; }

        private int testProperty2;
        // The delayed property is not implemented correctly.
        // [Delayed(true)] // Error
        // public int TestProperty2 { 
        //     get { return testProperty2; }
        //     set { SetPropertyValue(nameof(TestProperty2), ref testProperty2, value); }
        // }
    }
}

Valid Code

using DevExpress.Xpo;
using System;

namespace TestApplication.Module.BusinessObjects { 

    public class TestClass : XPObject { 
        public TestClass(Session session): base(session) {}  

        private XPDelayedProperty testProp1 = new XPDelayedProperty();

        // The property that meets the requirements
        [Delayed(nameof(testProp1), true)]
        public Byte[] TestProp1 {
            get { return (Byte[])testProp1.Value; }
            set { testProp1.Value = value; }
        }

        // The property that meets the requirements
        [Delayed(true)]
        public Byte[] Image {
            get { return GetDelayedPropertyValue<Byte[]>(nameof(Image)); }
            set { SetDelayedPropertyValue<Byte[]>(nameof(Image), value); }
        }
    }
}

How to Fix

Ensure a delayed property uses the GetDelayedPropertyValue<T>() and SetDelayedPropertyValue<T>() methods in its getter and setter, respectively.