c# - Task<ObservableCollection<AppointmentItem>> 不包含 where 的定义

标签 c# azure xamarin task observablecollection

我正在尝试按保存在其中的日期过滤可观察集合。用户将使用日历 View 选择日期。

public async Task RefreshItems(bool showActivityIndicator, bool syncItems)
        {
            using (var scope = new ActivityIndicatorScope(syncIndicator, showActivityIndicator))
            {

                var items = manager.GetAppointmentItemsAsync();


                CalendarVM vm = new CalendarVM();
                calendar.SetBinding(Calendar.DateCommandProperty, nameof(vm.DateChosen));
                calendar.SetBinding(Calendar.SelectedDateProperty, nameof(vm.DateSelected));
                calendar.BindingContext = vm;

                var filtered = items.Where(appointmentItem => appointmentItem.Date == SelectedDate);
            }
        }

以下是 AppointmentPage 类中的代码,其中包含用户选择的日期和数据。

  public async Task<ObservableCollection<AppointmentItem>> GetAppointmentItemsAsync(bool syncItems = false)
        {


            try
            {

                IEnumerable<AppointmentItem> items = await appointmentTable
                                        .ToEnumerableAsync();

                return new ObservableCollection<AppointmentItem>(items);

            }
            catch (MobileServiceInvalidOperationException msioe)
            {
                Debug.WriteLine(@"Invalid sync operation: {0}", msioe.Message);
            }
            catch (Exception e)
            {
                Debug.WriteLine(@"Sync error: {0}", e.Message);
            }
            return null;

        }

这是 dataManger 类中用于从数据库检索数据的代码。

目前我收到此错误:

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

最佳答案

您的以下代码行:

var items = manager.GetAppointmentItemsAsync();

返回 Task显然不包含 Where这就是您收到错误的原因。

请将此行更改为:

var items = await manager.GetAppointmentItemsAsync();

然后你会得到一个 ObservableCollection<AppointmentItem> 类型的集合其中应该有 Where成员(member)。

关于c# - Task<ObservableCollection<AppointmentItem>> 不包含 where 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43559299/

相关文章:

c# - Visual Studio 2015 C# 将应用程序部署到桌面

c# - 在 C# 中为多个消费者分割一个 FileStream

python - 尝试验证 Power Bi Web 应用程序时,重定向 url 不返回授权代码

c# - Xamarin.Forms:IValueConverter 只工作一次

c# - NotSupportedException 无法激活 JNI 句柄 - MvvmCross

c# - 在 Android (Xamarin) 上实现 Office 365 API 的问题

c# - 在 asp.net web 应用程序中处理用户上传文件的标准做法

c# - 如何以编程方式格式化未分配的空间?

azure - 如何授权服务在没有用户交互的情况下使用 Microsoft Graph 用户帐户?

function - Azure 函数 Blob 存储日期时间输出路径