The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

How to: Validate an Object

This example demonstrates how to prevent the Name property from being set to an empty string. If this property is set to an empty string, XPO throws a RequiredPropertyValueMissing exception.

public class RequiredPropertyValueMissing: Exception {
    public RequiredPropertyValueMissing(XPObject theObject, string propertyName):
        base(String.Format("The {0} property of the {1} object with id {2} must have a value", 
          propertyName, theObject.GetType().Name, theObject.Oid)) {

public class Company : Person {
public string Name = "";
    protected override void OnSaving() {
        if (Name == "")
          throw new RequiredPropertyValueMissing(this, "Name");
See Also