I want to expose a list of services from my DB or just return one service detail via Web API with my EF DBmodel
. I used VS2012 Web API scaffolding, quite easy so far and it works and return the list of services in JSON
when I hit the URL(.../api/Services)
. The problem is that when I want to obtain just one service URL(.../api/Services/1)
, I still obtain the full list of all services although when I trace it seems to return only a count of 1 object.
What happening here?
Here are the 2 controller actions.
ps: I also tried using a .Where()
instead of .Find()
but the result is the same in both cases.
// GET api/Services
public IEnumerable<service> Getservices()
{
var services = db.services.Include(s => s.Category).Include(s => s.Country).Include(s => s.StateProvince).Include(s => s.Territory);
return services.AsEnumerable();
}
// GET api/Services/5
public service Getservice(int id)
{
service service = db.services.Find(id);
if (service == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
return service;
}