Can I replace following function
public async Task<User> GetUserAsync(int id)
{
return await _dbContext.Users.SingleAsync(id);
}
with:
public Task<User> GetUserAsync(int id)
{
return _dbContext.Users.SingleAsync(id);
}
Can I replace following function
public async Task<User> GetUserAsync(int id)
{
return await _dbContext.Users.SingleAsync(id);
}
with:
public Task<User> GetUserAsync(int id)
{
return _dbContext.Users.SingleAsync(id);
}
I'm going to make a plausible assumption here: _dbContext.Users.SingleAsync(id);
returns a Task<User>
.
It's bad style to use async
when you can just call a single function that returns a Task
of the right type. It will handle the async
for you. Your code size will be smaller, and your generated code size will be much smaller.
Controversial opinion: If there's a single async
in the middle it should be replaced with Task.ContinueWith()
.