Azure 表 - 如何更新值
Azure Tables - How to update a value
这真的很基础,但我找不到帮助我的资源,这是我的实体:
public class PetEntity : TableEntity
{
public PetEntity(String petName)
{
this.PartitionKey = petName;
}
public PetEntity() { }
public int lvl { get; set; }
public int exp { get; set; }
public int hp { get; set; }
public int ap { get; set; }
public int dp { get; set; }
}
我做了一个循环,将所有宠物的当前 hp 增加 1,看起来是这样的:
foreach (PetEntity entity in table.ExecuteQuery(query))
{
entity.hp++;
Trace.TraceInformation("HP of {0} enhanced to {1}.", entity.PartitionKey, entity.hp);
}
问题是增强 HP 会更新第一个输出,但下次我达到 entity.hp 它保持不变,该值不会更新。
注意 - 它到达实体,这不是问题所在。
一旦您更改其中一个值,您必须手动 replace the entity:
foreach (PetEntity entity in table.ExecuteQuery(query))
{
entity.hp++;
table.Execute(TableOperation.Replace(entity));
Trace.TraceInformation("HP of {0} enhanced to {1}.", entity.PartitionKey, entity.hp);
}
这真的很基础,但我找不到帮助我的资源,这是我的实体:
public class PetEntity : TableEntity
{
public PetEntity(String petName)
{
this.PartitionKey = petName;
}
public PetEntity() { }
public int lvl { get; set; }
public int exp { get; set; }
public int hp { get; set; }
public int ap { get; set; }
public int dp { get; set; }
}
我做了一个循环,将所有宠物的当前 hp 增加 1,看起来是这样的:
foreach (PetEntity entity in table.ExecuteQuery(query))
{
entity.hp++;
Trace.TraceInformation("HP of {0} enhanced to {1}.", entity.PartitionKey, entity.hp);
}
问题是增强 HP 会更新第一个输出,但下次我达到 entity.hp 它保持不变,该值不会更新。
注意 - 它到达实体,这不是问题所在。
一旦您更改其中一个值,您必须手动 replace the entity:
foreach (PetEntity entity in table.ExecuteQuery(query))
{
entity.hp++;
table.Execute(TableOperation.Replace(entity));
Trace.TraceInformation("HP of {0} enhanced to {1}.", entity.PartitionKey, entity.hp);
}