Search for existing suggestions

Make Data Annotations more flexible to use and to customize

DataAnnotations are only really useful when the rules and the error messages can buble the whole way up to the ui. Some modern ui frameworks already make use of this - e.g. Breeze. But DataAnnotations are just not as flexible as we need them. Some known problems are:

- you can define your own error messages within the DataAnotation - but those are not easy to localize. To my mind the decission about displaying the content error message should be left to the client. As the client could possibly be a web page, a smartphone or even a coffee machine (think of IoT) the error message displayed by the client could be a localized string, an error number, a icon/symbol or some audio file. DataAnnotations should make it possible to categorize an error and give it a unique id to that the client can respond. They certainly could contain a default message, but that may not be suitable for any client or any user. Maybe the error should not be a simple string but rather a transportable exception or JSON class (dependend on the client). The client could even include a kind of "expected error media type" in his request or header.

- Data validations are not always as easy to do as checking a maximum length of a field or making a field mandatory. Sometimes we have complex validations that rely on the value of other properties of that particular entity or even may rely on values of other entities. For examble the validation could allow a field to be empty if another field is also empty but require it to be filled if some other field is filled also. To my mind there is a strong need for complex custom validation rules. Even a kind of optional "rules engine" may be appropriate so we may add validations containing regular expressions.

2 votes
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)

We’ll send you updates on this idea

Gerold shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • Gerold commented  ·   ·  Flag as inappropriate

    Oh, I just saw that I couldn't edit my post. So here are some additions I did forget:

    Since the EF7 story is not only about relational data - thinking about non-relational data stores like document databases there may be validation rules that limit the document size or do a kind version control. Another idea brings in a universal interface so that validation classes or even whole business rules engines could easy be plugged in to do complex data validations. Even triggering stored procedures in the database could be a possible szenario for data validation.

    If there was a kind of universal standard for sending the errors to the clients that goes further than those stupid http error codes, ui frameworks could easily follow those standards and display error messages in a appropriate way (think of message boxes on web clients, short messages on smartphones, error symbols an microwaves and little blinking error lights on coffee machines).

Feedback and Knowledge Base