正在关注 this tutorial作为指南 (OData/EntityFramework/Asp.Net)。
我能够在根目录上执行一个简单的 GET 命令。
{
"@odata.context": "http://localhost:49624/$metadata",
"value": [
{
"name": "Appointments",
"kind": "EntitySet",
"url": "Appointments"
},
......
{
"name": "Clients",
"kind": "EntitySet",
"url": "Clients"
}
]
}
但是任何比这更复杂的都会给我一个错误信息。 (我使用的是空 routePrefix。)
http://localhost:49624/Services
给我:
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:49624/Services'.",
"MessageDetail": "No type was found that matches the controller named 'Services'."
}
这是我的 super 简单的 GET
[EnableQuery]
public IQueryable<Service> Get()
{
return db.Services;
}
如果重要的话,我正在使用 Postman测试这些命令。尽管我认为这不是一个因素。
我有一个数据库和每个表的 DbSet。我不知道为什么我无法访问其中的任何内容。
WebApi配置:
config.MapHttpAttributeRoutes();
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Appointment>("Appointments");
builder.EntitySet<Service>("Services");
builder.EntitySet<Employee>("Employees");
builder.EntitySet<Client>("Clients");
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: null,
model: builder.GetEdmModel());
如果这是一个基本问题,我很抱歉,但我对这一切真的很陌生,而且已经在这堵墙上待得太久了哈哈。
最佳答案
上面的 Jan Hommes 指出 Controller 类需要复数(在我的例子中是 ServiceController -> ServicesController)
关于asp.net - 找不到与所有表的请求 URI (...) 匹配的 HTTP 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28616932/