我试图通过保存的日期筛选一个observablecollection。用户将使用日历视图选择日期。
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类中的代码,用于从数据库中检索数据。
目前,我收到此错误:
错误CS1061'任务>'没有
包含“ Where”的定义,没有扩展方法“ Where”
接受类型的第一个参数
可以找到“任务>”(您是
缺少using指令或程序集引用?
最佳答案
您的以下代码行:
var items = manager.GetAppointmentItemsAsync();
返回一个显然不包含
Task
的Where
,这就是为什么会出现错误的原因。请将此行更改为:
var items = await manager.GetAppointmentItemsAsync();
然后您将返回一个
ObservableCollection<AppointmentItem>
类型的集合,该集合应具有Where
成员。