等待 Azure 移动服务 TableController 中的 InsertAsync 错误

await InsertAsync error in Azure Mobile Service TableController

我的代码运行良好,但现在在等待 InsertAsync 函数时,我的所有 TableControllers 都出现错误。这是代码:

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

错误说: Cannot await System.Threading.Tasks.Task<sampleAppService.DataObjects.Account> expression.

我不知道是什么原因造成的。有帮助吗?

编辑

InsertAsync 函数的签名

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

根据 Sebi 的上述建议,我所要做的就是将 .Net Framework 目标从 4.5 to 4.5.1 更改为我的情况。 这为我解决了错误。

假设您的 InsertAsync() 正在执行一些内部等待的异步操作,您的 InsertAsync() 方法签名必须修改为包含异步词:

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