0
votes

enter image description here

 public async Task<IEnumerable<Users>> GetAllUsers()
        {
               return (await firebase
              .Child("Users")
              .OnceAsync<Users>()).Select(item => new Users
              {
                  UserName= item.Object.UserName.ToString(),
                  Password = item.Object.Password.ToString(),
                  Role  = item.Object.Role.ToString()
              }).ToList();
        }

I am a beginner to App development. While retriving the data from the Firebase Realtime database getting the above error. Scratching head for 4 hours. Please help.

1
What does your Users collection look like on firebase?Woj
I won't be able to see your project, take a screenshot of it.Woj
@Woj pls check now.user3403111

1 Answers

1
votes

You don't have to cast it toString(). Firebase casts types on its own, when you push that object on Firebase Realtime database, it will automatically assign correct type when you pull it back.Get rid of the ToString() on each property and see if that fixes the issue.

public async Task<IEnumerable<Users>> GetAllUsers()
    {
           return (await firebase
          .Child("Users")
          .OnceAsync<Users>()).Select(item => new Users
          {
              UserName= item.Object.UserName,
              Password = item.Object.Password,
              Role  = item.Object.Role
          }).ToList();
    }