Back to Devexpress

XAF0011: Implement the delayed property correctly

expressappframework-403726-debugging-testing-and-error-handling-code-diagnostics-xaf0011.md

latest2.5 KB
Original Source

XAF0011: Implement the delayed property correctly

  • Jan 27, 2022
  • 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

csharp
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

csharp
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.