Xamarin.Forms 如何从 firebase 实时数据库获取 ID 节点(密钥)

How to get ID node (key) from firebase realtime database on Xamarin.Forms

我有一个这样写的 firebase 实时数据库:

"Users" : {
    "6SuuMBbymrV0YaiE82YCU8Qz0bj1" : {
      "Name" : "Vincent",
      "e-Mail" : "vinc.dl@gmail.com"
    }

我想获取 ID (6SuuMBbymrV0YaiE82YCU8Qz0bj1) 并将其放入字符串变量中,以便我可以在查询询问中使用它(使用 where)。 .Key 和 .Uid 不起作用,那我该怎么做呢?

首先,我们将使用 FirebaseDatabase.net 包创建 Firebase 客户端。

FirebaseClient firebase = new FirebaseClient("Firebase Database URL");

用户模型

public class User
    {
        public string Name { get; set; }
        public string e-Mail { get; set; }

        public string Key { get; set; } //To Store ID
    }

获取用户的 Firebase 查询

await firebase
              .Child("Users")
              .OnceAsync<User>()).Select(item => new User
              {
                  Key = item.Key, // This is the ID
                  Name = item.Object.Name,
                  e-Mail = item.Object.e-Mail
              }).ToList();