Best solution for EF 4.1 + MVC + JSON circular reference exception? Best solution for EF 4.1 + MVC + JSON circular reference exception? json json

Best solution for EF 4.1 + MVC + JSON circular reference exception?


Use a view model and AutoMapper to map between your domain models and the view model which you will be sending to the view. This way you have total control over what properties are sent to the view which as a consequence reduces the amount of data sent between the server and the client. Also because now you are using view models your code is more resilient to modifications in your domain entities. If you modify them, only the mapping layer will be affected and thus you will not ever need to touch to your controllers or views.

So my advice is to download AutoMapper, read the documentation and start using it. It's a life changer, believe me.