After some tests, I realized that [PastConstraint] and [FutureConstraint] are working with local time. It is common for projects I have worked on to deal with dates in UTC on the backend side (service and database) and only convert to local time at the presentation layer (could be single or multiple local time display). But then I found that it was easy enough to implement custom constraints and so I made 2 additional constraints [PastUtcConstraint] & [FutureUtcConstraint]. Very nice to be able to easily define new constraints :-) I still have a problem with [FutureConstraint]. During the tests, it appeared that ALL defined entity validations are performed as soon as a single property is changed on a given entity. This is not problematic for time invariant validations (string length, number range, …) but it is problematic for [FutureContraint] because any change to an entity at a future time will eventually fail the validation on a [FutureConstraint] property that was set sometime in the past. Then I thought that I could fix this using ContrainMode=OnSetValue, which I thought would evaluate the constraint ONLY when I set the corresponding DateTime property but this did not work as it seems the validation is still performed when I change other properties. Is anyone aware of a trick I have not figured out yet? Thanks, Patrick |
Hello Peter, You are right, the property constraints are being checked whenever they have Mode property set to OnValidate or OnSetValue. We'll fix this shortly. The issue is fixed, updated binaries will be ready within several days. Thanks a lot for this quick fix! Patrick DataObjects.Net 4.3.7 & 4.4 beta 2 is released. 1
Yes indeed, it works nicely now even with my custom UTC constraints. Thanks again. |