I have the following database:
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:
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.
CodePudding user response:
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);