xamarin 将firebase数据转换为字符串变量

cidc1ykv  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(105)

I have a problem with saving data from firebase in string. While i try to display data i saved from list to string i get the
System Collection Generic List with model instead of the string data
Getting the data from firebase:

public async Task<List<StudentModel>>GetAll()
    {
        return (await firebaseClient.Child(nameof(StudentModel)).OrderByKey().LimitToLast(1).OnceAsync<StudentModel>()).Select(item => new StudentModel
        {

           
            Id = item.Key
            

        }).ToList();
    }

Convert and display

var students = await studentRepo.GetAll();
    

        string key = students.ToString();

        await DisplayAlert("a", key, "a");

I dont understand why it happens, also if someone knows an easier way to do it i would love to hear it. Thanks

juud5qan

juud5qan1#

studentRepo.GetAll返回**List<StudentModel>**。您正试图将其转换为单个字符串。请更新查询以返回字符串,或者使用students[0].Id只提取键值

相关问题