Skip to content

Posts from the ‘Entity Framework 4.0’ Category

26
Sep

Producing JSON from Entity Framework 4.0 generated classes

Currently our favorite web-development framework is ASP.NET MVC 2.0 and out favorite ORM technology is EntityFramework. ASP.NET MVC is first web-framework shipped by Microsoft where View and Controller is really separated, so we are taking all advantages from this. We are using Controller and depending on “call extension” (no extension, .xml, .json, .xlsx, .html) we are producing different output, for example:

/User/Details => produces render of whole page with masterpages, controls, etc
/User/Details.xml => responds with data returned by Controller and serialized to XML
/User/Details.json => responds with data returned by Controller and serialized to JSON
/User/Details.xlsx => responds with a generated Excel file with output of Cotroller
/User/Details.html => returns strict html to represent just data returned from Controller

This approach allows to use one Controller and produce different views.  You can read about more about implementation of extension driven approach here => http://icanhascode.com/2009/05/simple-ror-respond_to-functionality-in-aspnet-mvc/

But we faced problems most users facing while using EntityFramework and who needs to return JSON response from objects generated by EntityFramework. Read more »