我有 ac# 项目,我正在尝试使用FireSharp更新对象的单个值。但是,当我这样做时,它会删除其他字符串对象。
tldr 问题:
是否可以使用 Firesharp 仅更新对象的单个字段,还是在更新时必须包含所有字段?
在他们 GitHub 上的示例中,他们将所有字段设置为:
var todo = new Todo {
name = "Execute SET",
priority = 2
};
SetResponse response = await _client.SetAsync("todos/set", todo);
Todo result = response.ResultAs<Todo>(); //The response will contain the data written
然后他们使用以下内容更新字段:
var todo = new Todo {
name = "Execute UPDATE!",
priority = 1
};
FirebaseResponse response =await _client.UpdateAsync("todos/set", todo);
Todo todo = response.ResultAs<Todo>(); //The response will contain the data written
我知道这在其他语言中是可能的,所以我觉得这在 FireSharp 中应该是可能的。
我的情况:
例如,如果我有一个像 StudentProfile 这样的类:
class StudentProfile {
public string Firstname {get; set;}
public string Lastname {get; set;}
public int Age {get; set;}
}
当我上传到 firebase 时,我使用:
StudentProfile studentProfile = new StudentProfile
{
Firstname = "John",
Lastname = "Doe",
Age = 18
};
client.Set("Students/" + firebaseUserId + "/StudentProfile", studentProfile);
现在假设我想更新年龄。首先我会得到信息:
var result = client.Get("Students/" + firebaseUserId + "/StudentProfile");
StudentProfile student = result.ResultAs<StudentProfile>();
现在我只想更新年龄。但是,这似乎是更新Age但随后删除其他字符串值的地方
int newAge = student.Age + 1;
StudentProfile updatedStudent = new StudentProfile
{
Age = newAge
};
client.UpdateAsync("Students/" + firebaseUserId + "/StudentProfile, updatedStudent)
是否可以使用 Firesharp 仅更新对象的单个字段,还是在更新时必须包含所有字段?
基本上,如果我每次想要更新某些内容时都必须始终如一地写出所有字段,那将是一种痛苦。