我在 Firebase 中有以下資料庫:

每當我嘗試更新某些專案時,它都會洗掉未更改的專案,而不是讓它們保留其值。我有以下代碼:
FirebaseClient firebaseClient = new FirebaseClient("FirebaseLink");
MyDatabaseRecord databaserecord = new MyDatabaseRecord
{
Plate1 = EntryPlate1.Text.ToString(),
Plate2 = EntryPlate2.Text.ToString()
};
string restName = "Rest1";
await firebaseClient.Child("Menus/" restName).PutAsync(databaserecord); //Adicionar reload à página 2 após o click no bot?o de adicionar ou noutro click
EntryPlate1.Text = "";
EntryPlate2.Text = "";
MyDatabaseRecord.cs:
public class MyDatabaseRecord
{
public string Plate1 { get; set; }
public string Plate2 { get; set; }
}
我所說的“它洗掉未更改的”的意思是,在這個例子中,雖然我唯一的更改是對“Plate1”和“Plate2”的值,但當它執行時,它會從資料庫中洗掉“Plate3”,而不是僅僅替換我的目標。
我可以對我的代碼進行哪些更改以使其按預期作業?
uj5u.com熱心網友回復:
該PutAsync方法等效于 Firebase REST API 的 HTTP PUT 呼叫,它使用您傳遞到呼叫中的資料重寫給定路徑中的資料。如果您想修補資料,請使用PatchAsync它執行選擇性更新,僅覆寫您傳入的屬性。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/459771.html
