Pergunta

Eu tenho de dados em DataServiceCollection EquipBookings , mas a partir desta lista que deseja filtrar dados , como por data selecionada a partir de dados do seletor

por isso eu tento escrever isso, mas ele não está funcionando :

eu tenho de erro "não consegue converter implicitamente o tipo de lista para Dataservicecollection

  private DateTime _seletedDateChanged;
        public DateTime SeletedDateChanged
        {
            get { return _seletedDateChanged; }
            private set
            {
                _seletedDateChanged = value; 

                         // here i filter collections

                EquipBookings = FilterJobs(_seletedDateChanged);
                NotifyPropertyChanged("SeletedDateChanged");
            }
        }

        public DataServiceCollection<EquipBooking> FilterJobs(DateTime SeletedDateChanged)
        {
            return EquipBookings.Where(c => c.CreatedOn == SeletedDateChanged).ToList();
        }

Código completo é :

        #region EquipBookings
        // Define the binding collection for EquipBookings.
        private DataServiceCollection<EquipBooking> _equipBookings;

        public DataServiceCollection<EquipBooking> EquipBookings
        {
            get { return _equipBookings; }
            private set
            {
                _equipBookings = value;
                _equipBookings.LoadCompleted += OnEquipBookingLoaded;
                NotifyPropertyChanged("EquipBookings");
            }
        }
        public void LoadEquipBookingsData()
        {
            _context = new THA001_devEntities(_rootUri);
            EquipBookings = new DataServiceCollection<EquipBooking>(_context);
            var query = _context.EquipBooking.Expand("Status").Where(x => x.Status.Description.ToLower() == "confirmed").OrderBy(d => d.BookedFromDteTme);
            EquipBookings.LoadAsync(query);
            IsDataLoaded = true;
        }

        private void OnEquipBookingLoaded(object sender, LoadCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                IsDataLoaded = false;
                if (EquipBookings.Continuation != null)
                {
                    EquipBookings.LoadNextPartialSetAsync();
                    EquipBookingList = EquipBookings;
                }
            }
        }
Foi útil?

Solução

Isso retorna uma lista:

return EquipBookings.Where(c => c.CreatedOn == SeletedDateChanged).ToList();

Enquanto o tipo de retorno de seu FilterJobs o método é DataServiceCollection<EquipBooking> e não há nenhuma conversão implícita entre os dois.O compilador não entender como converter de um para o outro.

Você poderia fazer algo assim:

public DataServiceCollection<EquipBooking> FilterJobs(DateTime SeletedDateChanged)
    {
        var equipBookings = EquipBookings.Where(c => c.CreatedOn == SeletedDateChanged);
        var dataServiceCollection = new DataServiceCollection<EquipBooking>(equipBookings);

        return dataServiceCollection;

    }

Há uma sobrecarga de construtor DataServiceCollection o que leva uma IEnumerable{T} (um IEnumerable de EquipBookings no seu caso) como um parâmetro.Convenientemente, isso é exatamente o que o EquipBookings.Where(c => c.CreatedOn == SeletedDateChanged); retorna.

Outras dicas

Você precisa converter genérico IEnumerable para ObservableCollection.Você pode escrever um método de extensão para fazer esta conversão.Exemplos são aqui apresentadas como bem Como converter IEnumerable para ObservableCollection?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top