1

There are lots of tutorials for flattening domain models into DTO using AutoMapper. I am using Entity framework and I want to flatten my Domain models into DTO to send across my service which is implemented in WCF. The DTO will then be used as view models in my MVC presentation layer.

I am confused with what I do with the DTO after it has been updated by the view. There seems to be numerous blogs wondering why you would unflatten the DTO back to a domain model:

http://lostechies.com/jimmybogard/2009/09/18/the-case-for-two-way-mapping-in-automapper/

Product –> ProductDTO

ProductDTO –> Product

I assumed this is the approach I would take. What do I do with the DTO after its been updated and sent back across WCF? How do I commit it to the DB if its not a domain model? Or should I use a different mapper like ValueInjecter to achieve flattening and unflattening?

ministrymason
  • 1,783
  • 2
  • 20
  • 33

1 Answers1

1

In your UpdateProduct method, you can basically

  1. attach the detached entity to the database context
  2. set the entity as modified
  3. save changes

See these links for more detailed information:
The Entity Framework In Layered Architectures
Building N-Tier Apps with EF4
Entity Framework Service Layer Update POCO

Edit
Also see this question: Using AutoMapper to unflatten a DTO where the accepted answer is to basically use ValueInjector

Community
  • 1
  • 1
Rami A.
  • 10,302
  • 4
  • 44
  • 87