In asp.net Web Api2, when you create an async ASI controller for an entity infrastructure model, by default the first method in the new controller looks like this:
public IQueryable<MyModel> GetMyModel()
{
return db.MyModel;
}
The JSON output from this method is just an array of all the records MyModel. Meanwhile, all other methods for POST, PUT, GET (int id) and DELETE are marked as asyncreturn Task<IHttpActionResult>. Why not the first GET method in the same style, something like this:
public async Task<IHttpActionResult> GetMyModel()
{
return Ok(await db.MyModel.ToArrayAsync());
}
I tried this and it produces identical JSON output.
source
share