c# - Can't route to methods in BaseController when Derived is using ODataRoute -
i'm having problems routing basecontroller
controllers define [odataroute]
s.
- get ~/odata/foos works
- get ~/odata/foos(1) works
- get ~/odata/foos(1)/bars works
- get ~/odata/bars 404 not found
basecontroller
public abstract class basecontroller<t> : odatacontroller t : class { protected igenericrepository<t> repository; public basecontroller(igenericrepository<t> repository) { repository = repository; } [enablequery] public ihttpactionresult get() // <---------- problem { return ok(repository.asqueryable()); } [enablequery] public ihttpactionresult get(int key) // works { var entity = repository.getbykey(key); return ok(entity); } }
controllers
public class fooscontroller : basecontroller<foo> { public fooscontroller(igenericrepository<foo> repository) : base(repository) { } // can route base without problems // both base.get() , base.get(1) works } public class barscontroller : basecontroller<bar> { public fooscontroller(igenericrepository<bar> repository) : base(repository) { } // can't route base.get() // base.get(1) works // /foos(1)/bars [enablequery] [odataroute("foos({key})/bars")] public ihttpactionresult getbars(int key) // works { var result = repository.asqueryable().where(x => x.fooid == key); return ok(result); } }
additionally tried going convention way. doesn't work either.
public class fooscontroller : basecontroller<foo> { public fooscontroller(igenericrepository<foo> repository) : base(repository) { } // /foos(1)/bars [enablequery] public ihttpactionresult getbars(int key) // works { var result = repository.asqueryable().bars; return ok(result); } }
Comments
Post a Comment