I'm trying to create an ODataController that supports casting action.
Let's say we have Shape class and Circle class that derives from Shape
namespace NS
{
public abstract class Shape {
int Id;
int X;
int Y;
}
public class Circle : Shape {
int Radius;
}
}
And I want to create controller ShapesController.
public class ShapesController: ODataController
{
ShapesContext db = new ShapesContext();
[EnableQuery]
public IQueryable<Shape> Get()
{
return db.Shapes;
}
[EnableQuery]
public SingleResult<Shape> Get([FromODataUri] int key)
{
IQueryable<Shapes> result = db.Shapes.Where(p => p.Id == key);
return SingleResult.Create(result);
}
}
Everything work fine for request like
/odata/Shapes
/odata/Shapes(1)
But requests like
/odata/Shapes(1)/NS.Circle
cause 404 error
Referring to routing conventions http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-routing-conventions I have to create action like that
[EnableQuery]
public SingleResult<Circle> GetCircle([FromODataUri] int key)
{
IQueryable<Shapes> result = db.Shapes.Where(p => p.Id == key).Cast<Circle >;
return SingleResult.Create(result);
}
But it does not help - 404.
How can i make my controller support casting? Or maybe my approach is completely wrong and I misunderstand the principles?
Thanks