0

I am trying to update an entry in a table called Request. This table contains columns such as "Name" and "Accepted". I only want to update the "Accepted" field (which holds a boolean value) so that it becomes true. I only want it to be updated if certain conditions are met, i.e. the "Name" in the database is the same as that in a textbox.

private IMobileServiceTable<Request> requestTable= App.appClient.GetTable<Request>();
private MobileServiceCollection<Request, Request> requests;

requests= await requestTable
        .Where(c => c.Name == txtName.Text)
        .ToCollectionAsync();

//what should I put here to update Accepted to true?

await requestTable.UpdateAsync(requests);

How can I modify this code so that it will update Accepted to true, but only for the rows where the name matches?

Any help would be appreciated, thank you.

1 Answers1

1

You can do it like this.

codes.ForEach(p => p.Request = true);

Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48
  • Thank you for your reply. Unfortunately that still isn't working for me. It is giving a red squiggly line under "Foreach" saying that DataModel.Code doesn't contain a definition for 'ForEach'. Is there something that I'm missing from it? – PhoenixFirenzy Apr 21 '15 at 19:52
  • @PhoenixFirenzy , can you try `ToListAsync` instead of `ToCollectionAsync` or can you typecast `code` to `IEnumerable` and then try `.ForEach`. ForEach is a lambda expression applies to all ienumerable objects, it should work! – Arindam Nayak Apr 22 '15 at 05:25
  • Yes, you had done, what I told you, It should work, by the way, what is the error? - is it for lambda expression .ForEach? – Arindam Nayak Apr 22 '15 at 08:32
  • @PhoenixFirenzy, make sure you have `using System.Linq` and if still .ForEach is not working, then you can manually use `foeach() {}` loop to do that, ultimately that shortened expression expands to this - http://stackoverflow.com/questions/15449160/list-foreach-not-found – Arindam Nayak Apr 22 '15 at 08:56