locked
Field validation fails to validate RRS feed

  • Question

  • I am trying to validate a field named "Priority" that is defined as a tinyint (byte) in SQL Server (value between 0 and 255).

    This is my code:

    partial void Priority_Validate(EntityValidationResultsBuilder results)
            {
                if (this.Priority > 250 || this.Priority < 0)
                {
                    results.AddPropertyError("Priority between 0 and 250");
                }
            }

    It works only if the user enters 251 up to 255.

    If the user enters -1 or 2000 for example, I get a non-friendly message like:

    "Value entered is not valid, reverted to previous value...." (it never goes into my validator).

    Can you help please?

    Thanks,

    Gizi Ben-Tovim

    Sunday, August 10, 2014 1:21 PM

Answers

  • The easiest solution would be to use an INT instead of a TINYINT for this field.

    A more complicated solution would be to add an Integer screen variable for the user to enter data into, validate that Integer value and, if valid, copy the value into the TINYINT in the entity for storage.


    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    • Marked as answer by Angie Xu Friday, August 15, 2014 7:05 AM
    Tuesday, August 12, 2014 8:22 AM

All replies

  • The easiest solution would be to use an INT instead of a TINYINT for this field.

    A more complicated solution would be to add an Integer screen variable for the user to enter data into, validate that Integer value and, if valid, copy the value into the TINYINT in the entity for storage.


    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    • Marked as answer by Angie Xu Friday, August 15, 2014 7:05 AM
    Tuesday, August 12, 2014 8:22 AM
  • Thanks Simon, this was very helpfull!
    Monday, September 1, 2014 8:55 AM