ASP.NET MVC ModelCopier

Posted by shiju on Weblogs See other posts from Weblogs or by shiju
Published on Wed, 28 Apr 2010 03:39:00 GMT Indexed on 2010/04/28 3:43 UTC
Read the original article Hit count: 788

Filed under:

 In my earlier post ViewModel patten and AutoMapper in ASP.NET MVC application, We have discussed the need for  View Model objects and how to map values between View Model objects and Domain model objects using AutoMapper.
ASP.NET MVC futures assembly provides a static class ModelCopier that can also use for copying values between View Model objects and Domain model objects. ModelCopier class has two static methods - CopyCollection and CopyModel.CopyCollection method would copy values between two collection objects and CopyModel would copy values between two model objects.

<PRE class="c#" name="code">
 var expense=new Expense();
 ModelCopier.CopyModel(expenseViewModel, expense);

The above code copying values from expenseViewModel object to  expense object.
For simple mapping between model objects, you can use ModelCopier but for complex scenarios, I highly recommending to using AutoMapper for mapping between model objects.

© Weblogs or respective owner

Related posts about ASP.NET

Related posts about ASP.NET MVC