Consider the following two pieces of code. Both return data to a Web API Get call. Both return a list of items. Both work. The first one was taken from Visual Studio starter Blazor Wasm App. The second one was taken from an online tutorial. tblTitles is a table in a remote database, accessed through _dataContext.
Which of these should be used and why? Or perhaps one suits better for a specific situation?
[HttpGet]
//First method:
public IEnumerable<TitlesTable> Get()
{
var titles = _dataContext.tblTitles.ToList();
return titles;
}
//Second method:
public async Task<IActionResult> Get()
{
var titles = await _dataContext.tblTitles.ToListAsync();
return Ok(titles);
}