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

XAF0009: Properties decorated with the RuleRequiredFieldAttribute should be of nullable or reference type

Severity: Error

XAF requires that the properties decorated with the RuleRequiredFieldAttribute attribute must be of nullable or reference type. Otherwise, the validation rule does not work.

This diagnostic works only for XPO and EF Core business classes.

Examples

Invalid Code

using System; 
using DevExpress.Persistent.Validation; 

namespace TestApplication.Module.BusinessObjects { 
    public enum TitleOfCourtesy { Dr, Miss, Mr, Mrs,  Ms }; 

    public class TestClass { 
        // The property must be nullable
        //[RuleRequiredField] // Error: XAF0009 
        //public virtual int TestValueProperty {get; set;} 

        // The property must be nullable or of reference type
        //[RuleRequiredField] // Error: XAF0009 
        //public virtual TitleOfCourtesy TestEnumProperty {get; set;} 
    } 
} 

Valid Code

using System;
using DevExpress.Persistent.Validation;

namespace TestApplication.Module.BusinessObjects {
    public class TestClass {
        // The property that meets the requirements
        [RuleRequiredField]
        public virtual int? TestIntProperty {get; set;}

        // The property that meets the requirements
        [RuleRequiredField]
        public virtual ReferenceClass TestReferenceProperty {get; set;}
    }
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

How to Fix

Check the business object’s property declaration and ensure the property is of nullable or reference type.