Pretty easy to do with NH Validator.  There is one catch if you lazy load 
during validation (because of the late event it is running in), it will 
lead to the DefaultFlushEventListener throwing an exception.  It isn't 
necessary for it to do so & it will not block persistence if you ignore it 
using the event listener code below.

public class YourObjectValidationDef : ValidationDef<YourObject> {
    
public YourObjectValidationDef() {
    this.ValidateInstance.By((obj, context) => {
        context.DisableDefaultError();
        bool valid = (obj.Index == 0 || obj.StartDate >= 
obj.Parent.Children[obj.Index - 1].EndDate);
        if (!valid)
            context.AddInvalid("Add your error message here", "StartDate");
        return flag;
    });
}


    public class FlushFixEventListener : DefaultFlushEventListener {

        public override void OnFlush(FlushEvent @event) {
            try {
                base.OnFlush(@event);
            }
            catch (AssertionFailure) {
                // throw away
            }
        }
    }

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/wb36s3uB0-YJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to