开发者

MVC mapping viewmodels to POCOs

开发者 https://www.devze.com 2023-01-27 23:34 出处:网络
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.

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开发者_如何学C advance


Sounds like a job for AutoMapper

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

0

精彩评论

暂无评论...
验证码 换一张
取 消