February, 2014
DBContext & DBSet
DbContext: Is a simplified alternative to ObjectContext and is the primary object for interacting with a database using a specific model. DbSet: Is a simplified alternative to ObjectSet and is used to perform CRUD operations against a specific type from the model. DbContext and DbSet is used for the CodeFirst approach. Which enables a very […]
ASP.NET Web API to return JSON or XML data
Add the below code app_start event in global.asax file.In API Url add the query string. //json GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add( new QueryStringMapping(“type”, “json”, new MediaTypeHeaderValue(“application/json”))); //xml GlobalConfiguration.Configuration.Formatters.XmlFormatter.MediaTypeMappings.Add( new QueryStringMapping(“type”, “xml”, new MediaTypeHeaderValue(“application/xml”))); eg: for xml : http://localhost:49533/api/books?type=xml for json: http://localhost:49533/api/books?type=json Favorite