Asp.net MVC WebAPI 和 OData 调试小记

1、在VS2013上调试不成功 很多包版本不一致

2、在VS2015 上调试成功 按照如下链接提供的例子:

https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

3、WebAPI 调试成功后,增加OData支持,参照链接:http://www.telerik.com/blogs/using-kendo-ui-with-mvc4-webapi-odata-and-ef

Install-Package Microsoft.AspNet.WebApi.OData -Pre
4、增加OData支持

public IEnumerable<Product> GetAllProducts()
{
return products;
}

改为

[Queryable]
public IQueryable Get()
{

return products.AsQueryable();
}

5、Global.asax.cs 增加:

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);



posted @ 2017-01-17 14:31  InvApp  阅读(362)  评论(0编辑  收藏  举报