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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With