I am trying to figure out what is the best way to select data via Entity Framework with async await. In the following code I have two options.
The first uses Task.FromResult.
The second option tries to use the async await keywords to optimize the code.
1.
public Task<IEnumerable<DesignExample>> ExecuteAsync(GetAllExamplesQuery query)
{
var designExamples = _copyDataDb.DesignExamples.OrderBy(dE => dE.Order).Select(DesignExample.MapFromEntity);
return Task.FromResult(designExamples);
}
2.
public async Task<IEnumerable<DesignExample>> ExecuteAsync(GetAllExamplesQuery query)
{
var designExamples = await _copyDataDb.DesignExamples.OrderBy(dE => dE.Order).ToListAsync();
return designExamples.Select(DesignExample.MapFromEntity);
}
- Does the second option increase overall performance in relation to the first?
- The second option will await the call to the database, but will that really give me any benefits in this scenario?