protected virtual void UpdateOperations() { EnosixServiceOrder_OPERATIONS[] operations = new EnosixServiceOrder_OPERATIONS[] { }; if (null != ServiceOrder && null != ServiceOrder.OPERATIONS_Collection) { operations = ServiceOrder.OPERATIONS_Collection.ToArray(); } // If any plants are defined on the timesheet then filter the operations list if (null != TimeSheet && null != TimeSheet.PLANT_Collection && TimeSheet.PLANT_Collection .Any(p => p.StartDate < p.EndDate && !string.IsNullOrWhiteSpace(p.Plant))) { var dateFrom = TimeSheet.DateFrom; var dateTo = TimeSheet.DateTo; // Only select plants that are valid for the timesheet range var plants = TimeSheet.PLANT_Collection .Where(p => p.StartDate <= dateFrom && p.EndDate >= dateTo) .Select(p => p.Plant).ToArray(); // Filter the operations by plant operations = operations .Where(o => plants.Contains(o.Plant)) .ToArray(); } lock (_operations) { int i = 0; _operations = Enumerable.ToArray( from operation in operations select new ServiceOrderOperationViewModel(this, i++, operation) ); } RaisePropertyChanged(() => Operations); }