I have this base 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);
}
}
And this derived controller
public class FoosController : BaseController<Foo>
{
}
I can hit .../odata/foos(1)
just fine. But .../odata/foos
give this error:
{
"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": ""
}
}
}
I have to make Get()
virtual and then override it in the derived controller. Like this:
public class FoosController : BaseController<Foo>
{
[EnableQuery]
[ODataRoute("Foos")]
public override IHttpActionResult Get()
{
return base.Get();
}
}
Why doesn't Get()
in the base controller work, when Get(1)
does?