0
votes

I have a "small" enterprise application, aspnet mvc 3 + entity framework with POCO entity and repository pattern. I structured the solution in 4 projects:

  1. POCO entities
  2. Domain model
  3. Services
  4. web application

When the application performs a query on the database, use one of the services provided, the service uses the repository and the small classes, as a result I have some dynamic proxy objects that I would like to convert in my domain entities, before using them in mvc views, but I do not know how. Dovrebber be set as the translator?

This approach is reasonable?

2
What I normally do is create "ViewModel" classes that represent the data that will be passed into my views. These classes can have validation attributes if you have input forms, or other metadata. As suggested by @ekolis , you could use AutoMapper or just manually map the POCO entities to your ViewModel classes. This is also some times necessary for me since there are times that my POCO entities have circular references and forces me to translate to a different class that doesn't.Makotosan

2 Answers

0
votes

AutoMapper is handy for converting objects from one type to another. It will generally "do the right thing" if all your destination type properties have correspondingly named source type properties, and any nonmatching properties can easily be mapped manually using lambda expressions.

0
votes

Not sure what the "small classes" being used are, but I assume you will want to use some IOC to be able to inject your repository into the service layer. See more here: http://msdn.microsoft.com/en-us/magazine/dd942838.aspx#id0420033