0

我有这个基础 ODataController

public abstract class BaseController<T> : ODataController where T : class
{
    [EnableQuery]
    public IHttpActionResult Get()
    {
        return Ok(Repository.AsQueryable());
    }

    [EnableQuery]
    public IHttpActionResult Get(int key)
    {
        var entity = Repository.GetByKey(key);
        return Ok(entity);
    }
}

而这个派生的控制器

public class FoosController : BaseController<Foo>
{

}

我可以打得.../odata/foos(1)很好。但是.../odata/foos给出这个错误:

{
    "error": {
        "code": "",
        "message": "No HTTP resource was found that matches the request URI 'https://localhost:44300/odata/Foos'.",
        "innererror": {
            "message": "No action was found on the controller 'Foos' that matches the request.",
            "type": "",
            "stacktrace": ""
        }
    }
}

我必须创建Get()虚拟,然后在派生控制器中覆盖它。像这样:

public class FoosController : BaseController<Foo>
{
    [EnableQuery]
    [ODataRoute("Foos")]
    public override IHttpActionResult Get()
    {
        return base.Get();
    }
}

为什么Get()在基本控制器中不起作用,什么时候起作用Get(1)

4

0 回答 0