Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#Firesharp-如何更新对象的单个值?_C#_Firebase_Firebase Realtime Database_Fire Sharp - Fatal编程技术网

c#Firesharp-如何更新对象的单个值?

c#Firesharp-如何更新对象的单个值?,c#,firebase,firebase-realtime-database,fire-sharp,C#,Firebase,Firebase Realtime Database,Fire Sharp,我有一个c#项目,我正在尝试使用更新对象的单个值。但是,当我这样做时,它会删除其他字符串对象 tldr问题: 是否可以使用Firesharp仅更新对象的单个字段,或者在更新时必须包含所有字段 在GitHub上的示例中,他们将所有字段设置为: var todo = new Todo { name = "Execute SET", priority = 2 }; SetResponse res

我有一个c#项目,我正在尝试使用更新对象的单个值。但是,当我这样做时,它会删除其他字符串对象

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
当我上传到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>();
是否可以使用Firesharp仅更新对象的单个字段,或者在更新时必须包含所有字段


基本上,如果每次我想更新某些内容时都必须一致地写出所有字段,那将是一种痛苦。

最简单的方法是将左侧的路径扩展到age,然后使用
SetAsync

client.GetAsync(
  "Students/" + firebaseUserId + "/StudentProfile/Age", 
  newAge
)

我会尝试github讨论页面:@Jazb,我以前从未知道它的存在。谢谢你指出这一点。我也会在那里试试。
var result = client.Get("Students/" + firebaseUserId + "/StudentProfile");

StudentProfile student = result.ResultAs<StudentProfile>();
int newAge = student.Age + 1;

StudentProfile updatedStudent = new StudentProfile 
{
   Age = newAge
};

client.UpdateAsync("Students/" + firebaseUserId + "/StudentProfile, updatedStudent)
client.GetAsync(
  "Students/" + firebaseUserId + "/StudentProfile/Age", 
  newAge
)