简体   繁体   English

UpdateAsync不适用于Azure移动服务

[英]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: 我正在尝试使用以下代码使用.NET客户端更新Windows Azure移动服务数据库中的行:

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. XID属性只是我自己添加的整数键,与所需的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. 在本地将TITLE属性正确设置为“新标题”,但是当执行UpdateAsync命令并且将鼠标悬停在“ myItem”实例上时,我看到TITLE属性已恢复为原始值。
  • 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. 测试代码时,我破坏了GUID,并且UpdateAsync失败,因为在我的表中没有该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. 现在,我要先运行DeleteAsync命令,然后再运行InsertAsync,然后就可以了。 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. 但是我对为什么UpdateAsync命令对我不起作用以及为什么在执行时会用原始数据刷新“ myItem”实例感到困惑。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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