Return Json Using PetaPoco Dynamic & WebAPI

asp.net-mvc-4, c#, c#-4.0, json, petapoco

Solution

JSON.Net handles this out of the box, so I Had to add a Custom Formatter.

This is the MSDN article I used to resolve the issue: http://code.msdn.microsoft.com/Using-JSONNET-with-ASPNET-b2423706

Problem

Is it possible to use PetaPoco dynamic query to return Json in the ASP.net WebAPI? //WebAPI Controller ``` public class BranchController : ApiController { public IEnumerable<dynamic> Get() { // Create a PetaPoco database object var db = new PetaPoco.Database("DefaultConnection"); // Show all Branches var b = db.Query<dynamic>("SELECT * FROM Branches").ToList(); return b; } } ``` I am receiving an error To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object)

Original source