0

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?

Snæbjørn
  • 10,322
  • 14
  • 65
  • 124
  • What does `Repository.AsQueryable()` do? `Repository.GetByKey(key)` calls a method of your repository, but the first one looks odd to me. Shouldn't it be something like `Repository.GetEverythingMEthod().AsQueryable()`? – Marco Oct 27 '15 at 09:40
  • `Repository.AsQueryable()` is just `DbSet.AsQueryable()`. I stripped out the injection of `Repository` because that shouldn't have anything to do with the routing :) – Snæbjørn Oct 27 '15 at 10:05

0 Answers0