Skip to main content
All docs
V24.1
.NET Framework 4.5.2+

XAF0023: Do not implement IObjectSpaceLink in the XPO classes

Severity: Warning

Do not implement the IObjectSpaceLink interface in an XPO class. Instead, use the Session property to query or modify data inside a persistent class. Use IObjectSpace only in XAF Controllers.

Examples

Invalid Code

using DevExpress.Xpo;

namespace TestApplication.Module.BusinessObjects {
    // Do not implement IObjectSpaceLink in the XPO classes
    public class BaseObject1 : BaseObject, IObjectSpaceLink { // Warning
        public BaseObject1(Session session) : base(session) {}

        public IObjectSpace ObjectSpace { get; set; }
        public bool IsDirty { 
            get { 
                // Use ObjectSpace only in XAF Controllers
                return ObjectSpace.IsObjectToSave(this) || ObjectSpace.IsNewObject(this); 
            } 
        }
    }
}

Valid Code

using DevExpress.Xpo;

namespace TestApplication.Module.BusinessObjects {
    public class BaseObject1 : BaseObject {
        public BaseObject1(Session session) : base(session) {}

        public bool IsDirty { 
            get { 
                // This code meets the requirements
                return Session.IsObjectToSave(this) || Session.IsNewObject(this); 
            } 
        }
    }
}