Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to define your own database ID – Firebase Xamarin

I have the following database:
enter image description here

And I want to use the "Nome" value as an ID instead of a generated code. Instead of -MzKveR8JIXgWsrph_or I wanted it to be Teste1.

My current insert code looks like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 MyDatabaseRecord databaserecord = new MyDatabaseRecord
            {
                Nome = EntryNome.Text.ToString(),
                Prato1 = EntryPrt1.Text.ToString(),
                Prato2 = EntryPrt2.Text.ToString(),
                Sopa = EntrySopa.Text.ToString(),
                Contacto = EntryContacto.Text.ToString()
            };

            firebaseClient.Child("Restaurantes").PostAsync(databaserecord);

What do I need to change in order to set the decided value as a Firebase ID? I’ve been trying to get there but couldn’t yet find the right answer.

>Solution :

The Firebase Realtime Database API for C# follow a REST-ful pattern for its method names. This means that calling POST on a URL creates a resource under that location with an identifier determined by the system. If you want to determine your own identifier, call PUT on the entire path (including that identifier).

So:

firebaseClient.Child("Restaurantes/RestaurantOne").PutAsync(databaserecord);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading