M
M
Max Suprunenko2016-01-09 15:51:19
JSON
Max Suprunenko, 2016-01-09 15:51:19

How to translate Entity framefork data into json data in WEB API?

How to translate Entity framefork data into json data? I use Angular + Web API.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2016-01-10
@msuprunenko

In App_Start/WebApiConfig.cs add to the Register method

var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
            config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);

            var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().FirstOrDefault();

            if (jsonFormatter != null)
                jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

in controller
public IQueryable<Order> GetOrders()
        {
            return _db.Orders;
        }

All.

D
Dmitry, 2016-01-09
@Venesuella

var result = query.ToArray();
return Json(result,JsonRequestBehaviour.AllowGet);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question