<p>In my <a href="https://stackoverflow.com/questions/39371/database-exception-handling-best-practices">previous question</a>, most commenters agreed that having validation logic both at client &amp; server sides is a good thing.</p>
<p>However there is a problem - you need to keep your validation rules in sync between database and client code.</p>
<p>So the question is, how can we deal with it?</p>
<p>One approach is to use ORM techniques, modern ORM tools can produce code that can take care of data validation prior sending it to the server.</p>
<p>I'm interested in hearing your opinions.</p>
<p>Do you have some kind of standard process to deal with this problem? Or maybe you think that this is not a problem at all?</p>
<hr />
<p><strong>EDIT</strong></p>
<p>Guys, first of all thank you for your answers.</p>
<p>Tomorrow I will sum up you answers and update question's text like in <a href="https://stackoverflow.com/questions/39371/database-exception-handling-best-practices">this case</a>.</p>

[{'answer_id': 39654, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 2, 'selected': False, 'text': "<p>As mentioned in one of the answers to the other post, if you are going to keep your layers separated, there is no good way to avoid duplicating the validation logic in each layer.  If you use something to automatically tie them together, you have introduced a sort of coupling between the layers that might hinder you down the road.  This might be one of those cases where you just have to keep track of things manually.</p>\n\n<p>However you go about it, you have to make sure each layer is doing its own validation, because you never know how that layer is going to be accessed.  There's no guarantee that all the layers you implemented will always stay together.</p>\n"}, {'answer_id': 39683, 'author': 'user2870', 'author_id': 2870, 'author_profile': 'https://Stackoverflow.com/users/2870', 'pm_score': 2, 'selected': False, 'text': "<p>I like to use a validation service, which doesn't necessarily care about the origin of the data to be validated.  This can work in a few different ways when you get to the part about transmitting validation rules to a client (i.e. web page), but I feel the most important aspect of this is to have a single authority for the actual validation rules.</p>\n\n<p>For example, if you have validation logic on your data core entities, like a collection of ValidationRule objects that are checked via a Validate method - a very typical scenario, then I would promote those same rules to the client (javascript) via a transformation.</p>\n\n<p>In the ASP.NET world (the only one I can speak to) there are a couple of ways to do this.  My preferred method involves creating custom validators that tie in to your UI widgets to fields (and all their validation rules) on your entities.  The advantage of this is that all your validation logic can be bundled into a single validator.  The down side is that your validation messages will become dense, since the validation rules are all tested at once.  This can, of course, be mitigated by having your validation logic return only a mention of the first failure, etc.</p>\n\n<p>This answer probably sounds sort of nebulous and unspecific, but the two points that I'd like to make are:</p>\n\n<ol>\n<li>Validation should occur as close as possible to the points where data is entered and where it's committed.</li>\n<li>The same validation rules should be used wherever validation occurs - if client-side validation passes, then it should never fail validation later on (pre-save business rules, foreign key violation, etc.)</li>\n</ol>\n"}, {'answer_id': 39706, 'author': 'Marcio Aguiar', 'author_id': 4213, 'author_profile': 'https://Stackoverflow.com/users/4213', 'pm_score': 2, 'selected': False, 'text': '<p>Some framework provides a validation support the may keep your client and server validation in sync. Take a look at this <a href="http://weblogs.java.net/blog/bleonard/archive/2006/05/trying_out_jbos_1.html" rel="nofollow noreferrer">Seam validation tutorial</a> using annotations. It\'s a good implementation and very easy to understand.</p>\n\n<p>Anyway, if you don\'t wan\'t to rely on frameworks, I think it is easy to implement something similar.</p>\n'}, {'answer_id': 39708, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 1, 'selected': False, 'text': "<p>If you're using ASP.Net there are a number of validation controls you can use.  These controls are written in a very generic way, such that most of them automatically duplicate your validation logic between the client and server, even though you only set options for the control in one place.  </p>\n\n<p>You are also free to inherit from them to create additional domain specific validators, and there are third-party control packs on the web you can get that add to the base controls.</p>\n\n<p>Even if you're not using ASP.Net it's worth taking a look at how this is done.  It will give you ideas for how to do something similar in your own platform.</p>\n"}]
['https://Stackoverflow.com/questions/39628', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1196/']