step-up-labs / firebase-database-dotnet

C# library for Firebase Realtime Database.
MIT License
668 stars 168 forks source link

PutAsync deletes child from the parent. #276

Closed L10Messi10 closed 2 years ago

L10Messi10 commented 2 years ago

Does PutAsync really remove its child upon update? here is my code below.

`var evaluatesch = (await client .Child("Schools") .OnceAsync()).FirstOrDefault (a => a.Object.SchoolID == sch_id);

            if (evaluatesch != null)
            {
                Schools school = new Schools
                {
                    SchoolID = schoolid,
                    SchoolName = schoolname,
                    SchoolAddress = schooladdress,
                    DateTimeSubscription = subscriptiondt,
                    Status = stat
                };

                await client
                    .Child("Schools")
                    .Child(evaluatesch.Key)
                    .PutAsync(school);
                client.Dispose();
                return true;
            }

            client.Dispose();
            return false;`

Assuming that the database has been added with another child (Teachers) then upon executing the above code which updates the parent node, the child (Teacher) will be deleted. Here is the screenshot after executing the above code.

putasyncfirebase .

cabauman commented 2 years ago

You didn't add a before screenshot so I assume Teachers is a child of School. In that case, yes, put replaces the whole node. You can either include teachers in your put operation or use patch instead of put.

L10Messi10 commented 2 years ago

Yes, (Teachers) is the child of the School. Thank you for your feedback, PatchAsync solved the issue.