OrmLight DataAnnotations Range

Is there a DataAnnotation that can be used to exclude some values. In this case, I want to exclude 0 as a possible value but any other valid long value should be accepted.

I use this property to store some epoch value with ms precision.

If I do not provide any value to the property EpochMs it gets persisted with a value of 0.

I tried using the Range data annotation but it still persist to 0.

        [Required]
        [Range(1,long.MaxValue)]
        public long EpochMs { get; set; } //ex.: 1558110941194

You can use a [CheckConstraint], e.g:

[CheckConstraint(nameof(EpochMs) + " > 0")]
public long EpochMs { get; set; } //ex.: 1558110941194

Super. That works. Thanks!

1 Like