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

时间:2015-10-27 00:22:40

标签: parse-platform xamarin

我有一个在线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;

1 个答案:

答案 0 :(得分:0)

在您的示例中,您将获得对象的列表(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();