未找到与所有表的请求URI(...)匹配的HTTP资源

sta*_*rd7 1 asp.net http odata entity-framework-6

本教程为指导(OData/EntityFramework/Asp.Net).

我能够在root上执行一个简单的GET命令.

{
"@odata.context": "http://localhost:49624/$metadata",
"value": [
    {
        "name": "Appointments",
        "kind": "EntitySet",
        "url": "Appointments"
    },

    ......

    {
        "name": "Clients",
        "kind": "EntitySet",
        "url": "Clients"
    }
]
}
Run Code Online (Sandbox Code Playgroud)

但是比这更复杂的东西给了我一个错误信息.(我正在使用null routePrefix.)

http://localhost:49624/Services
Run Code Online (Sandbox Code Playgroud)

给我:

{
    "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'."
}
Run Code Online (Sandbox Code Playgroud)

这是我超级简单的GET

[EnableQuery]
public IQueryable<Service> Get()
{
    return db.Services;
}
Run Code Online (Sandbox Code Playgroud)

如果重要的话我正在使用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());
Run Code Online (Sandbox Code Playgroud)

我很抱歉,如果这是一个基本问题,但我对这一切都很陌生,已经在这个墙上已经太久了哈哈.

sta*_*rd7 5

Jan Hommes上面指出控制器类需要多元化(在我的例子中是ServiceController - > ServicesController)