When writing async functions, usually if you do not explicitly writer await
or async
your compiler would throw an error or warning. Example of correct syntax below:
public async Task<List<TEntity>> GetEntitiesAsync() =>
await TEntityRepository.GetAllAsync();
Now the following works still, it is async and returns a Task<List>
public Task<List<TEntity>> GetEntitiesAsync() =>
TEntityRepository.GetAllAsync();
Why does the second one still work
Both calls return the same Task, so they are the effectively the same.
In order to use "await" in a method, that method MUST be labeled async. Since the second one doesn't use await, it doesn't need to be labeled async.
That's it.
With that said, it probably isn't a good ideas to do this as there are some pitfalls as described in the article mentioned by @TheGeneral: https://blog.stephencleary.com/2016/12/eliding-async-await.html