我正在尝试按保存在其中的日期过滤可观察集合。用户将使用日历 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/