Yes, I know there are other questions to cover what this warning means and how to solve it, however, I have a question about best practices regarding async programming.
I have a service layer which handles data transfer between the data layer and the presentation layer. This service contains several methods which query the database, and return the result.
I have been trying to use async programming wherever possible. An example:
public async Task<SiteTemplateResource[]> GetResources(int siteTemplateId, string extension)
{
return await Database.FindBy<SiteTemplateResource>(str => str.SiteTemplateId == siteTemplateId && str.HashedFile.EndsWith(extension)).ToArrayAsync();
}
My problem with this is, I'm not actually awaiting anything, other than to the ToArrayAsync call, which I don't really need.
Should I go ahead and use async/await for this? And how would I for example await anything for this function:
public async Task<int> SiteTemplateBySiteIdAsync(int siteId)
{
return Database.First<SiteSiteTemplate>(sst => sst.SiteId == siteId).SiteTemplateId;
}
I don't await anything in that function, but I also don't need to call ToArrayAsync, so how do I avoid the warning "method lacks 'await' operator" in above case?
Thanks in advance.