简单流程:我正在从容器中获取项并对其进行迭代。请更改属性并再次存储。
方法获取项
public async Task<ActionItem[]> GetActionsNotExecutedAsync(string transferId)
{
QueryDefinition query = new("SELECT * FROM c WHERE c.TransferId = @transferId AND c.Executed = @executed");
query.WithParameter("@transferId", transferId);
query.WithParameter("@executed", false);
QueryRequestOptions opts = new QueryRequestOptions();
opts.PartitionKey = new PartitionKey(transferId);
opts.MaxItemCount = -1;
List<ActionItem> actions = new();
using FeedIterator<ActionItem> feed = _action.GetItemQueryIterator<ActionItem>(query);
while (feed.HasMoreResults)
{
foreach (ActionItem action in await feed.ReadNextAsync())
{
actions.Add(action);
}
}
return actions.ToArray();
}
方法来更新项
public async Task UpdateActionAsync(ActionItem item)
{
//await _transfer.UpsertItemAsync<ActionItem>(item, new PartitionKey(item.TransferId));
await _transfer.ReplaceItemAsync<ActionItem>(item, item.id);
}
同时使用两种方法的代码
ActionItem[] actions = await db.GetActionsNotExecutedAsync(evt.TransferId);
foreach (ActionItem action in actions)
{
action.Executed = true;
await db.UpdateActionAsync(action);
}
我希望看到属性“Executed”更改为TRUE,但在使用ReplaceItemAsync()时却得到404。使用UpsertItemAsync()时没有错误,但属性也没有更改。
1条答案
按热度按时间djmepvbi1#
哦,我真是瞎了眼!我用了不同的容器 * shamonme *
如您所见,读取ActionItem的第一个方法使用名为“_action”的容器,更新ActionItem的第二个方法使用名为“_transfer”的容器。