ASP.NET MVC2 Posting a ViewModel mapping to Domain (LINQ) to Submitting changes -
I am using Automapper to map between the Linux domain object and a view model, which allows the user to edit a form Works perfectly to do .
When they click Submit, I want to know the best way to map ViewModel back into a Linux unit and keep it in the database.
This method works only when I am only updating properties that There are no collections, but throwing errors while trying to modify properties is the collection.
Any help / ideas will be highly appreciated :)
The approach is taken by Jimmy Bougard in the CodeCampServer project ().
I have a general mapper class which I need to override in a map-method model method, which maps from view modal to domain model, and a GetIdFromViewModel method that provides the proper ID To show the ViewModel so that the service level can obtain the domain model from the database.
I had to replace some CodeCampServer instances because some of my models used the grid and some used at the model for the model.
You should be able to get the code from the codepex link above
public class member on: Autoformmapper and lieutenant member, memberformmodel, guid & gt; at IMMBM {public member on Mapper (IMMBC Service Service): Base (Service) {} Safe Override Guided GIET Afromvy IewModel (MemberFormualModal ViewModel) {Return ViewModel.MemberID; } Protected Override Zero MadTellModel (MemberFormWeelModelViewModel, Member Models) {// If needed, then we will need to map the right things as foreign key properties / DB / DB We do not need this, So we do not waste the call model. Member Id = ViewModelMail ID; Model First name = viewmodel. first name; Model.ListName = viewModel.LastName; Model.Title = viewModel.Title; Model.EmailAddress = viewModel.EmailAddress; Model DirectX = View Model Direct phone Model Mobile phone = see model mobile phone; Model.ElectronicId = viewModel.ElectronicId; Model Project reel type id = View Model. Projectorolipid; Model.DepartmentId = ViewModel. Department id; }}
Then you can use this Member Mapper to map both directions. It uses Automapers to go from domain model to visual model and then uses the Maps-model model method which you apply to map back to model model from View model.
Comments
Post a Comment