我是odata的新手。我已经用控制器构建了一个Web api,如下所示:
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Web.OData.Routing;
namespace HelloWebApi.Controllers
{
public class TestsController : ODataController
{
//
// GET: /Product/
ProductsContext db = new ProductsContext();
private bool TestExists(int key)
{
return db.tests.Any(p => p.key== key);
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
[EnableQuery]
public IQueryable<test> Get()
{
return db.tests;
}
Run Code Online (Sandbox Code Playgroud)
模型如下图所示:
public class Test
{
[Key]
public int key { get; set; }
public string aaa { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我还配置了routeconfig,odataconfig,webapi config和global.asax文件,如下所示。
public class RouteConfig …Run Code Online (Sandbox Code Playgroud)