Azure 移动服务 InsertAsync 获取状态

Azure Mobile service InsertAsync Get Status

我正在插入我的 Azure 移动服务 SQL-数据库,它工作正常,但我想知道是否有错误,以便我可以更正它。

如何从 InsertAsync 获取状态以查看它是成功还是失败?

public static MobileServiceClient MobileService = new MobileServiceClient(
  "https://YOUR-DOMAIN.azure-mobile.net/",
  "YOUR-KEY"
);

static IMobileServiceTable<Product> productTable = MobileService.GetTable<Product>();

Product product = new Product { 
  name = NPDName.Text,
  description = NPDDescription.Text,
  price = NPDPriceExkl.Text,
  tax = NPDTax.Text,
  stock = NPDStock.Text,
  available = NPDCBAvailable.Checked,
  active = true
};

productTable.InsertAsync(product);

How do i get the status from the InsertAsync to see if it succeed or failed?

InsertAsyncreturns一个Task。如果你想知道它的状态,你需要await。如果失败,将传播异常:

public async Task InsertAsync()
{
    Product product = new Product
    { 
       name = NPDName.Text,
       description = NPDDescription.Text,
       price = NPDPriceExkl.Text,
       tax = NPDTax.Text,
       stock = NPDStock.Text,
       available = NPDCBAvailable.Checked,
       active = true
    };

    await productTable.InsertAsync(product);
}