Search code examples
entity-frameworkentity-framework-4.1data-annotationswcf-ria-services

Data Annotations - Not Zero


How do you annotate a numerical field that is required, and must not zero.... I have tried looking this up a couple of times, but can't find anything on it. Surely I can't be alone!

[Range(-9999999,-1)] is good for negative values only (is there a better way?)

OK - so how about NOT zero?

Range(1,9999999) and Range(-9999999,-1) - but two range attributes is incorrect. Is Custom attribute the only way to go?

Regards, R


Solution

  • I don't think you can do this using the standard validation attributes. As you say, you could use a custom attribute. Alternatively you could use someone else's library, for example MVC Foolproof validation appears to provide a NotEqualTo operator which you could use.