【问题标题】:updating a record using Windows Azure database (on windows phone)使用 Windows Azure 数据库更新记录(在 Windows Phone 上)
【发布时间】:2014-03-23 13:40:51
【问题描述】:

我是 windows azure(和 windows phone)的新手,我正在尝试弄清楚如何更新存储在 windows azure 中的记录。

我已使用以下代码成功插入记录:

public class Item
{
    public string Id { get; set; }
    public string type { get; set; }
    public int count { get; set; }
}

private async void insertRiskScore(Item item)
{
    await riskTable.InsertAsync(item);
}


private IMobileServiceTable<Item> riskTable = App.MobileService.GetTable<Item>();

var insertItem = new Item { type = "low", count = 0 };
insertRiskScore(insertItem);

var insertItem2 = new Item { type = "med", count = 0 };
insertRiskScore(insertItem2);

我的问题是......我将如何检索存储在数据库中的值并增加计数(例如,获取 type="low" 并增加计数的记录)。

谢谢!!

【问题讨论】:

    标签: c# .net azure windows-phone-8 azure-storage


    【解决方案1】:

    您应该使用 IMobileServiceTable 中的 Where 和 UpdateAsync 方法(就像您使用 InsertAsync 一样);对于搜索,您可以这样做:

    var table = client.GetTable<Item>();  
    
    var lowItem = (await table  
        .Where(  
          p => p.type == "low"
        )  
        .ToEnumerableAsync())  
        .Single();
    

    对于更新:

    if(lowItem != null){
        lowItem.count++;
        await table.UpdateAsync(lowItem);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多