This project is read-only.

Automapper And ViewModels

Apr 9, 2012 at 2:24 PM

So based on your reponse to my issue the other day I figured I would give you some feedback. Figured since I have been using this for the last week I would toss this out there.

Rather than return the actual entity objects back to the UI I have been using Automapper and creating views models that I then send back to the UI, so far this has worked really well.

2 issues that I had with returning the EF objects back to the UI were:

1. The sterilization issues that you run into (noted in the issue tracker) as well as some circular reference errors I was encountering when making ajax calls.

2. I was running EF Prof and noticed that when an object was serialized every navigational property that was touched caused an sql statement to be executed. This was undesired behavior. I have attached a photo ( I call was made to Page in the base Controller for 'Products' and the end results. What you'll see is that as each record was iterated a sql call was made for each navigational property. So in my case 22 sql statements were executed. That being said, we can override this call in the appropriate controller and solve this issue. Again I ended up going with Automapper and creating viewmodels.

For testing out this project I have been using both the AdventureWorks and AdventureWorksLT SQL 2008 DB's. Its an interesting DB to work with since you run into a couple of many to many tables, tables that don't have int's for primary keys, and tables that don't have updated/created date or update/created by fields. Because of this you get to explore the generated code a bit and make adjustments to get everything to work properly.

All in all this is an awesome application you have created. Im getting ready to show it to the rest of the team and I know they will be amazed. The ability to point this at an existing db and have all tiers of your application built is such a time saver. I appreciate all your hard work and keep up the good work.