سؤال

I am new to windows azure (and windows phone) and I am trying to figure out how to update a record which is stored within windows azure.

I have successfully inserted the record using the following code:

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);

My question is ... how would I retrieve the values stored on the database and increment the count (e.g. obtain a record where type="low" and increment count).

Thank you!!

هل كانت مفيدة؟

المحلول

You should make use of the Where and UpdateAsync methods from IMobileServiceTable (just as you used InsertAsync); For search you do this:

var table = client.GetTable<Item>();  

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

And for updating:

if(lowItem != null){
    lowItem.count++;
    await table.UpdateAsync(lowItem);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top