如何使用Xamarin更新Parse.com数据库中的对象



我有一个在线Parse.com数据库,我可以创建对象并查询它们,但不能更新。在Parse.com文档的Xamarin部分中,它只告诉您如何在创建对象后直接更新对象,而我不想这样做。我试着适应文档说的其他平台,但它没有工作,我也试过查询数据库,并在此之后直接输入新的字段值,但它将它们视为单独的功能。有人需要帮忙吗?

Parse.com文档:

    // Create the object.
var gameScore = new ParseObject("GameScore")
{
    { "score", 1337 },
    { "playerName", "Sean Plott" },
    { "cheatMode", false },
    { "skills", new List<string> { "pwnage", "flying" } },
};
await gameScore.SaveAsync();
// Now let's update it with some new data.  In this case, only cheatMode
// and score will get sent to the cloud.  playerName hasn't changed.
gameScore["cheatMode"] = true;
gameScore["score"] = 1338;
await gameScore.SaveAsync();

我最近尝试的:

ParseQuery<ParseObject> query = ParseObject.GetQuery("cust_tbl");
IEnumerable<ParseObject> customers = await query.FindAsync();
customers["user"] = admin;
record["score"] = 1338;
await record;

在您的示例中,您将获得一个对象列表(IEnumerable)而不是单个对象。相反,请尝试这样做:

ParseQuery<ParseObject> query = ParseObject.GetQuery("cust_tbl");
// you need to keep track of the ObjectID assigned when you first saved,
// otherwise you will have to query by some unique field like email or username
ParseObject customer = await query.GetAsync(objectId);
customer["user"] = admin;
customer["score"] = 1338;
await customer.SaveAsync();

最新更新