We have Application service Method, which extracts data from SQL database using Entity Framework Core . Its Async method along with the Async Controller.
Service:
public async Task<IEnumerable<ProductType>> GetProductTypeData()
{
var result = _dbContext.Set<ProductType>()
.Where(x => x.LkProcessActionTypeId > 0 && x.Status.HasValue && x.Status.Value).AsNoTracking()
.ToListAsync();
return await result;
}
API Controller:
[HttpGet("[Action]")]
public async Task<ActionResult<ProductType>> GetProductTypeAPI()
{
var response = await productService.GetProductTypeData();
return Ok(response);
}
Someone mentioned, its better practice to make Service method just Task, no Async (to avoid Double Async) Would there be any difference between, using Async or No Async in the application method?
The Service Method does not necessarily have to be utilized with the API.
New Application Method (No Async)
public Task<IEnumerable<ProductType>> GetProductTypeDto()
{
var result = _dbContext.Set<ProductType>()
.Where(x => x.LkProcessActionTypeId > 0 && x.Status.HasValue && x.Status.Value).AsNoTracking()
.ToListAsync();
}
Resource: This does not directly answer the question,
https://stackoverflow.com/questions/19098143/what-is-the-purpose-of-return-await-in-c