title: How to retrieve a single record from Firebase Real Time Database in Xamarin-Android?
body: <p>I need to read only one entity from Firebase Realtime Database and convert the result into a C# class matching the structure, but I haven't found a solution clear. Having this tree: </p>
  
  <pre><code>{
   "characters" : {
      "c1" : {
        "Email" : "peter.pan@example.com",
        "LastName" : "Pan",
        "Name" : "Peter"
      },
      "c2" : {
        "Email" : "harry.potter@example.com",
        "LastName" : "Potter",
        "Name" : "Harry"
      }
    }
  }
  </code></pre>
  
  <p>And this C# class: </p>
  
  <pre><code>public class Character 
  {
     public string Email {get; set; }
     public string Name { get; set; }
     public string LastName { get; set; }
  }
  </code></pre>
  
  <p>I would like to retrieve only one record by email, which I know and it is unique. But, if I do include the NuGet package <a href="https://www.nuget.org/packages/Xamarin.Firebase.Database/60.1142.1" rel="nofollow noreferrer">Xamarin.Firebase.Database</a> there not exists a method or extension method such as <code>OnceSingle&lt;T&gt;() or OnceSingleAsync&lt;T&gt;()</code> in it: </p>
  
  <pre><code>Character character = await FirebaseDatabase.Instance
    .GetReference(CharactersRoot)
    .OrderByChild("Email")
    .EqualTo("harry.potter@example.com") //Works until here
    .OnceSingleAsync&lt;Character&gt;(); //THIS METHOD IS NOT AVAILABLE. It doesn't work.
  </code></pre>
  
  <p>In the other hand, by including package <a href="https://www.nuget.org/packages/Xamarin.Forms.FirebaseWrapper/" rel="nofollow noreferrer">Xamarin.Forms.FirebaseWrapper</a>, an upgrade of the former <a href="https://github.com/rlamasb/Firebase.Xamarin" rel="nofollow noreferrer">Firebase.Xamarin</a>, that supports <code>OnceSingleAsync&lt;T&gt;()</code> one can code something like this: </p>
  
  <pre><code>FirebaseClient fbClient= new FirebaseClient(Root);
  var task = Task&lt;Character&gt;.Run(async () =&gt; 
              {
                  return await fbClient.Child(CharactersRoot)
                      .OrderBy("Email")
                      .EqualTo("harry.potter@example.com")
                      .OnceSingleAsync&lt;Character&gt;().ConfigureAwait(false)
              });                 
              var character = task.Result;
              // do something with character...
  </code></pre>
  
  <p>But it doesn't work. It raises a <strong>System.AggregateException: 'One or more errors occurred. (Response status code does not indicate success: 400 (Bad Request).)'</strong></p>
  
  <p>The following is the only I've managed to make it work, but it is under performant because it retrieves all the collection and performs the search locally.</p>
  
  <pre><code>    FirebaseClient fbClient= new FirebaseClient(Root);
      var task = Task&lt;Character&gt;.Run(async () =&gt;
              {
                  return await fbClient.Child(CharactersRoot)                                     
                                      .OnceAsync&lt;Character&gt;()
                                      .ConfigureAwait(false);
              });
              var character = task.Result
                              .Where(item =&gt; item.Object.Email == "harry.potter@example.com")
                              .Select(itm =&gt; itm.Object)
                              .FirstOrDefault();
              if (character != null)
              {
                  //Do something with character
              }
  </code></pre>
  
  <p>Any ideas that can help to clarify my mind to do it simpler and better will be appreciated.</p>