Skip to main content
All docs
V25.1
  • .NET 8.0+

    XAF0002: XPO business class properties should not be overridden

    • 2 minutes to read

    Severity: Warning

    XAF and XPO do not support the following business object’s properties:

    • Declared with the new keyword.
    • Overridden and virtual properties.
    • Abstract properties.

    For more information about these requirements, see the following article: Can I override properties of business objects?.

    This diagnostic works only for XPO classes derived from the DevExpress.Xpo.PersistentBase class. This diagnostic does not check static properties.

    Examples

    Invalid Code

    using DevExpress.Persistent.BaseImpl;
    using DevExpress.Xpo;
    
    namespace MySolution.Module.BusinessObjects {
        public class TestClass : TestClassBase {
            public TestClass(Session session) : base(session) { }
    
            private int testProperty1;
            // The property must not be virtual
            //public virtual int TestProperty1 { // Warning: XAF0002
            //    get { return testProperty1; }
            //    set { SetPropertyValue(nameof(TestProperty1), ref testProperty1, value); }
            //}
    
            private int testProperty2; 
            // The property must not override a property from a base class
            //public override int TestProperty2 { // Warning: XAF0002
            //    get { return testProperty2 + 1; }
            //    set { SetPropertyValue(nameof(TestProperty2), ref testProperty2, value); }
            //}
    
            private int testProperty3; 
            // The property must not be declared with the `new` keyword
            //public new int TestProperty3 { // Warning: XAF0002
            //    get { return testProperty3 + 1; }
            //    set { SetPropertyValue(nameof(TestProperty3), ref testProperty3, value); }
            //}
        }
    }
    

    Valid Code

    using DevExpress.Persistent.BaseImpl;
    using DevExpress.Xpo;
    
    namespace MySolution.Module.BusinessObjects {
        public class TestClass : TestClassBase {
            public TestClass(Session session) : base(session) { }
    
            private int testProperty;
            // The property that meets the requirements
            public int TestProperty { 
                get { return testProperty; }
                set { SetPropertyValue(nameof(TestProperty), ref testProperty, value); }
            }
        }
    }
    

    How to Fix

    Check the business object’s property declaration and ensure the property is declared without the following modifiers:

    • abstract
    • virtual
    • override
    • new