【发布时间】:2015-02-19 21:08:35
【问题描述】:
以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'."
}
这是我的超级简单的 GET
[EnableQuery]
public IQueryable<Service> Get()
{
return db.Services;
}
如果重要的话,我会使用Postman 来测试这些命令。虽然我认为这不是一个因素。
我为每个表都有一个数据库和一个 DbSet。我不知道为什么我无法访问这些。
WebApiConfig:
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());
如果这是一个基本问题,我很抱歉,但我对这一切真的很陌生,而且已经在这堵墙太久了哈哈。
【问题讨论】:
-
您的控制器的名称是什么?您必须将其命名为
ServicesController。 -
天哪...谢谢你修复它。 (以前是“ServiceController”)
标签: asp.net http odata entity-framework-6