You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xamarin Firebase实时数据库中OrderByChild无法使用的问题排查

问题:Firebase Realtime Database 查询报错:'ChildQuery' 没有 'OrderByChild' 定义

我在项目的MainPage.xaml文件中添加搜索功能,原本一切正常无报错,但添加根据搜索词查询Firebase数据库的SearchRasepiRecord()方法后出现问题。

相关代码

MainPage.xaml.cs

private async void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
    var searchTerm = e.NewTextValue;
    var records = await firebaseHelper.SearchRasepiRecord(searchTerm);
    displayRecord.ItemsSource = records;
}

FirebaseHelper.cs

public async Task<List<RasepiRecord>> SearchRasepiRecord(string searchTerm)
{
    var result = await firebase
        .Child("RasepiRecords")
        .OrderByChild("Food")
        .StartAt(searchTerm.ToLower())
        .EndAt(searchTerm.ToLower() + "\uf8ff")
        .OnceAsync<RasepiRecord>();

    return result.Select(item => new RasepiRecord
    {
        Name = item.Object.Name,
        Food = item.Object.Food,
        Ingredients = item.Object.Ingredients,
        Instructions = item.Object.Instructions,
        Meal = item.Object.Meal,
        Socmed = item.Object.Socmed,
    }).ToList();
}

报错信息

Error CS1061 'ChildQuery' does not contain a definition for 'OrderByChild' and no accessible extension method 'OrderByChild' accepting a first argument of type 'ChildQuery' could be found (are you missing a using directive or an assembly reference?)

已尝试的解决方法

  • 确保引用了正确的命名空间:
    using Firebase.Database;
    using Firebase.Database.Query;
    
  • 安装了最新版本的Firebase Realtime Database .NET SDK
  • 卸载后重新安装SDK
  • 清理并重建项目

请问使用VS2019会有影响吗?


内容的提问来源于stack exchange,提问作者Ameer Hakim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 10:12:55