简体   繁体   中英

UpdateAsync not Working for Azure Mobile Services

I'm trying to update a row in a Windows Azure Mobile Services Database with a .NET client using the following code:

List<TodoItem> myItemsList = await todoTable.Where(todoItem => todoItem.XID == 1).ToListAsync();
TodoItem myItem = myItemsList.First();
myItem.TITLE = "New Title";
await myClient.GetTable<TodoItem>().UpdateAsync(myItem);

The XID attribute is just my own integer key that I've added, different to the required guid. The problem is the update isn't going through. Some things to note are:

  • The retrieval part works fine when I'm debugging it. Locally the TITLE attribute gets set to "New Title" correctly, but when the UpdateAsync command gets executed and I mouse-over the 'myItem' instance I see the TITLE attribute has reverted back to its original value.
  • I corrupted the guid when testing the code, and the UpdateAsync failed as expected, since there is no record in my table with that guid.
  • I'm pretty sure this code was working before, now it's not.

For now I'm making do with running the DeleteAsync command, followed by the InsertAsync and that does the trick. But I'm baffled as to why the UpdateAsync command isn't working for me, and why when it does execute it refreshes the 'myItem' instance with the original data.

Not sure at all but if you are desperate try to change : (no reputation for comment)

List<TodoItem> myItemsList = await todoTable.Where(todoItem => todoItem.XID == 1).ToListAsync(); TodoItem myItem = myItemsList.First();

to :

TodoItem myItem = todoTable.Where(todoItem => todoItem.XID == 1).FirstOrDefault();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM