我有这个基础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)
不起作用?