I am trying to make my code more efficient and easier to manage, I have nested models in my crud views, some can be 4 tiers deep.
The base models also have fields which will need adding serverside, like employeeID's, date and time last modified and new concurrency variable.
now I was going to use automapper, but there seems to be very little information about using it to map nested models from forms to entity models to allow to update, there is also no information how add and removed is used for automapper (to add and removed
nested models)
and I don't want to waste my time if its not going to work, does someone have any guidelines or docs on the best plan of action so I can put it in place automapper or otherwise
Are you using a view model specific to each view? Automapper does allow you to flatten a model from a complex nested model to simple view model. That should cover sending the data to the view http://automapper.codeplex.com/wikipage?title=Flattening
However, you might want to apply a specialized factory object that's sole reponsbility is taking the view model and constructing your complex model based on what was returned to the mvc action. That way you are isolating the construction of the complex model
to one place.
EnenDaveyBoy
Participant
1465 Points
1146 Posts
Mapping issue, and big headache
Apr 03, 2012 02:32 PM|LINK
Hi
I am trying to make my code more efficient and easier to manage, I have nested models in my crud views, some can be 4 tiers deep.
The base models also have fields which will need adding serverside, like employeeID's, date and time last modified and new concurrency variable.
now I was going to use automapper, but there seems to be very little information about using it to map nested models from forms to entity models to allow to update, there is also no information how add and removed is used for automapper (to add and removed nested models)
and I don't want to waste my time if its not going to work, does someone have any guidelines or docs on the best plan of action so I can put it in place automapper or otherwise
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Mapping issue, and big headache
Apr 03, 2012 02:55 PM|LINK
For the auto mapper questions, you might get better replies at the automapper github issues page
https://github.com/AutoMapper/AutoMapper/issues
Are you using a view model specific to each view? Automapper does allow you to flatten a model from a complex nested model to simple view model. That should cover sending the data to the view
http://automapper.codeplex.com/wikipage?title=Flattening
The other way around, you , take a look at nested mappings
https://github.com/AutoMapper/AutoMapper/wiki/Nested-mappings
However, you might want to apply a specialized factory object that's sole reponsbility is taking the view model and constructing your complex model based on what was returned to the mvc action. That way you are isolating the construction of the complex model to one place.
Blog | Twitter : @Hattan