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);

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 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);
经验分享 程序员 微信小程序 职场和发展