step-up-labs / firebase-database-dotnet

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

How can I use the SetAsync method? #240

Closed hieucodecraft closed 3 years ago

hieucodecraft commented 4 years ago

Currently, I use the PostAsync() to push the object to Firebase and the response will return the generated key and the object. However, I would like to control the generated key, as UUID. I know the method set() in Firebase but there is no set method in the lib right now?

TheGocc commented 4 years ago

Hey, I just ran into the same problem yesterday, and I found out, that if you use e.g.: dictionary, (with using UUID for the dictionary's key), with put it generates and entry in the realtime database, with ID -> UUID.

`

            Dictionary<string, DbData> tmp = new Dictionary<string, DbData>();
            DbData userData = new DbData
            {
                Admin = false,
                Name = "Mr. QWE"
            };

            tmp.Add(data.User.LocalId, userData);

            await db.Child("users").Child(data.User.LocalId).PutAsync(userData);

`

If you have another UUID it will create another child in users

hieucodecraft commented 4 years ago

@TheGocc It's great. Thank for your support

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

Closing the issue due to inactivity. Feel free to re-open