Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC mapping viewmodels to POCOs

I am developing an ASP.NET MVC 3 application using EF 4 and POCOs. One of the main challenges that I have is how to map a ViewModel to a POCO.

For example:

I have two POCO object -> User and Order. Furthemore I have a ViewModel --> UserOrderModel containing both models. Whenever some data is posted I would like to map the UserOrderModel to a User and an Order object. It is pretty straightforward to do this (perhaps just map on request in the controller) but I am wondering if there is a nice, clean solution for that problem (I was initially thinking of creating a generic mapping interace for all view models so that they must define how to map themselves to a POCO object)

Thanks in advance

like image 227
sTodorov Avatar asked Dec 01 '10 09:12

sTodorov


1 Answers

Sounds like a job for AutoMapper

Great example here on mapping MVC ViewModel's to POCO's.

like image 185
RPM1984 Avatar answered Sep 27 '22 23:09

RPM1984