How to get firebase unique key in c# windows forms

Viewed 19

I am inserting an object of type WhatsappElement class

class WhatsappElements
{
    public string Number { get; set; }
    public string Message { get; set; }

}
WhatsappElements newwhatsapp = new WhatsappElements
  {
        Number = txt_number.Text+"&N",
        Message = txt_message.Text+"&M",
   };
   await client.PushAsync("WhatsappElements/Data" , newwhatsapp);

The data shows as follows

  -Data

-NBSUSIOSPPSWEIE

in the other app which I try to retrieve I use the following code

public async void getdAta()
    {
        var resp = await server.GetAsync("WhatsappElements/Data");
        WhatsappElements element = resp.ResultAs<WhatsappElements>();
        MessageBox.Show(element.Number);
        
    }

But it prints a blank , what am i doing wrong? or how can I get the data ? or even return the unique key?

1 Answers

Since you write the data with PushAsync, the database creates a new child node under Data with a unique key. When you read the value from Data, you have to cater for that key by iterating over the child nodes of the result.

You'll want to get the result as a Dictionary and then loop over entries or values in that dictionary.

Related