in

Chennai .Net User Group

A platform that enables you to Learn, Share & Grow (India's first .Net user group)

Shiju Varghese's Blog

ASP.NET MVC ModelCopier

 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. 

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.

Read the complete post at http://feedproxy.google.com/~r/ShijuVBlog/~3/sMcfIY_fvm0/asp-net-mvc-modelcopier.aspx

Only published comments... Apr 28 2010, 06:39 AM by Shiju Varghese's Blog
Filed under: ,
Copyright © 2002-2008 Chennai .Net User Group. All Rights Reserved. Microsoft and Microsoft logo's are trademarks of Microsoft Corporation