views:

481

answers:

3

I'm reading several docs on validation in ASP.NET MVC. Ignoring those that suggest to reinvent the wheel writing your own validation logic, most articles advocate the use of xVal or Data Annotation Validators, both of which allow declarative validation through decorating models' properties(*).

I think I'll go for xVal, as it seems to be the most suggested (and thus, I hope, supported). What puzzles me is that I'm using Linq to SQL, and my models are declared in an automatically generated file (dbml + partial.cs), containing several classes and almost 5000 lines long, so I'm not very eager to edit it, as if I change the db structure I'll have to regenerate it, loosing my changes.

Is there a way to avoid editing that file?


(*) I've also found a Validator Toolkit which also provides declarative validation and doesn't request to decorate models' properties, but the page shows 57 downloads, so I can't tell if the project is mature or not.

A: 

Yes it can (xVal). See here and here.

RichardOD
+2  A: 

You can create a partial class and add the Data Annotation Validators to the partial class that way it doesn't matter if your dbml file is regenerated.

Try this asp.net article and this article

David G
+1  A: 

Check out buddy classes -- really the only way to fly with generated models and DataAnnotation-based validation.

Wyatt Barnett
yes, it's the same solution suggested in the answer I accepted.
giorgian