I have a generic WebApi controller with CRUD operations like this:
public abstract class BaseController<TEntity> : ApiController where TEntity : class
{
protected abstract DbSet<TEntity> DatabaseSet { get; }
// GET: api/{entity}
[Route("")]
public IEnumerable<TEntity> GetAll()
{
return DatabaseSet;
}
// GET: api/{entity}/5
[Route("{id:int}")]
//[ResponseType(TEntity)] ToDo: is this possible? <---
public IHttpActionResult Get(int id)
{
TEntity entity = DatabaseSet.Find(id);
if (entity == null)
{
return NotFound();
}
return Ok(entity);
}
// ...
// and the rest
// ...
}
My question is about the commented-out [ResponseType(TEntity)]. This line does not work. Also not with typeof(TEntity). The error is 'Attribute argument can not use type parameters' Is there a way to make the ResponseType known for the generic type?
Thanks! Jasper