ASP.NET MVC ModelCopier
        Posted  
        
            by shiju
        on ASP.net Weblogs
        
        See other posts from ASP.net 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: 1043
        
ASP.NET
|ASP.NET MVC
 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);
</PRE>
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.
© ASP.net Weblogs or respective owner