I am using NHibernate for persistence and have my domain model mapped out. I am using MVC2 and I am keen to use the built in model validation for all basic validation (string length, range, etc).
The problem is that I’m finding that there is a huge amount of work involved in this. I have 26 POCO classes representing the domain. Which means I need roughly 5 x 26 = 130 ViewModels (one for create, edit, view, list, delete) given I’m going to use ViewModels everywhere. 130 ViewModels to create and maintain considering I have my domain objects already mapped out seems wasteful.
Now I’ve bought into the idea that this is a good way to develop as a way to keep the view as dumb as possible, eliminate view related security blunders, etc. To be honest I get the strong impression I’m missing a tool or technique that would speed this process up.
Is there a way to reduce this pain?
I’m not sure why you would need 5 ViewModels? The ViewModels kinda represent what you want to display (in the view):
Lets say you have these Related Entities:
You have three entities but from the form that creates the BlogArticle you’re writing the article, selecting tags and then choosing a category on one page.
On the BlogArticle create form you just want the following ViewModel:
You could use http://automapper.codeplex.com to map Models to ViewModels.