Posts

Showing posts from October, 2013

ASP.NET Web API doesn't play nice with Entity Framework's dynamic proxy classes.

Update 10/2016 - This posting is better viewed in my new blog . I have a Web API project which leverages an SQL database through Entity Framework. Pretty standard Microsoft technology stacks I've been using for years. When using EF I've historically disabled lazy loading and proxy generation due to lack of need for those features. This project I left them enabled. I quickly started getting serialization exceptions from my controller. A little googling and I found this is a known issue with the use of EF dynamic proxies and serialization (specifically JSON). Infinite reference loops can and often do appear in EF entities. Take the following example. public class Parent { public ICollection<Child> Children { get ; set ; } } public class Child { public Parent Parent { get ; set ; } } A Parent has references to many Children and each Child has a reference to the Parent. An infinite loop occurs when the serializer attempts to fully resolve either of