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

XAF0001: Implement XPO business class constructors correctly

  • 2 minutes to read

Severity: Error

XAF requires that the XPO business object’s constructor should:

Violation of these rules may lead to unexpected results. For example, the New Action may be hidden for this object.

This diagnostic works only for classes derived from the DevExpress.Xpo.PersistentBase class. This diagnostics does not work for abstract classes.

Examples

Invalid Code

using DevExpress.Persistent.Base; 
using DevExpress.Persistent.BaseImpl; 
using DevExpress.Xpo; 

namespace MySolution.Module.BusinessObjects{ 
    [DefaultClassOptions] 
    public class ExampleObject1 : BaseObject {
        // The constructor must be public
        // ExampleObject1(Session session) : base(session) {} // Error: XAF0001
    } 
    // ...

    [DefaultClassOptions] 
    public class ExampleObject2 : BaseObject {  
        // The constructor must take a Session object as a parameter
        // public ExampleObject2(){} // Error: XAF0001
    } 
    // ...

    [DefaultClassOptions] 
    public class ExampleObject3 : BaseObject {  
        // The constructor must pass a Session object 
        // as an argument to the base class constructor. 
        // public ExampleObject3(Session session){} // Error: XAF0001
    } 
    // ...

    [DefaultClassOptions]
    public class ExampleObject4 : BaseObject {
        // The constructor must not pass a DefaultSession object 
        // as an argument to the base class constructor. 
        // public ExampleObject4(Session session) : base(Session.DefaultSession) {} // Error: XAF0001
    }
    // ...

}

Valid Code

using DevExpress.Persistent.Base; 
using DevExpress.Persistent.BaseImpl; 
using DevExpress.Xpo; 

namespace MySolution.Module.BusinessObjects{ 
    [DefaultClassOptions] 
    public class ExampleObject1 : BaseObject {
        // This constructor meets the requirements
        public ExampleObject1(Session session) : base(session) {} 
    } 
    // ...
}