简体   繁体   中英

await InsertAsync error in Azure Mobile Service TableController

My code was working fine but right now I get an error on all my TableControllers when awaiting the InsertAsync function. This is the code:

 // POST tables/Account
    public async Task<IHttpActionResult> PostAccount(Account item)
    {
        Account current = await InsertAsync(item);
        return CreatedAtRoute("Tables", new { id = current.Id }, current);
    }

The error says: Cannot await System.Threading.Tasks.Task<sampleAppService.DataObjects.Account> expression .

I have no idea what's causing this. Any help?

EDIT

The signature of the InsertAsync function

protected virtual Task<TData> InsertAsync (TData item);

Based on Sebi's suggestion above, all I had to do was change the .Net Framework target from 4.5 to 4.5.1 in my case. That resolved the errors for me.

Assuming that your InsertAsync() is performing some async operation which is getting awaited inside, your InsertAsync() method signature must be modified to include the async word:

protected virtual async Task<TData> InsertAsync (TData item)
{
    await dbContext.InsertAsync(item);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM