public void Initialize()
        {
            this._dds                    = new DomainDataSource();
            this._dds.Loaded            += new RoutedEventHandler(this.DomainDataSourceLoaded);
            this._dds.LoadingData       += new EventHandler <OpenRiaServices.Controls.LoadingDataEventArgs>(this.DomainDataSourceLoadingData);
            this._dds.LoadedData        += new EventHandler <LoadedDataEventArgs>(this.DomainDataSourceLoadedData);
            this._dds.SubmittingChanges += new EventHandler <SubmittingChangesEventArgs>(this.DomainDataSourceSubmittingChanges);
            this._dds.SubmittedChanges  += new EventHandler <SubmittedChangesEventArgs>(this.DomainDataSourceSubmittedChanges);

            this._view              = this._dds.DataView;
            this._view.PageChanged += this.ViewPageChanged;
            this._collectionView    = this._view;
            this._collectionView.CollectionChanged += this.ViewCollectionChanged;
            this._editableCollectionView            = this._view;
            this._pagedCollectionView = this._view;

            this._comboBox = new ComboBox {
                Name = "_comboBox"
            };
            this._comboBox.Loaded += new RoutedEventHandler(this.ComboBoxLoaded);

            this._textBox = new TextBox {
                Name = "_textBox"
            };
            this._textBox.Loaded += new RoutedEventHandler(this.TextBoxLoaded);

            this.ResetLoadState();
            this.ResetPageChanged();
            this.ResetSubmitState();

            this._asyncEventFailureMessage = null;
        }
        /// <summary>
        /// Updates the query by calling <see cref="SortBy{TEntity}(QueryBuilder{TEntity},ICollectionView)"/> and <see cref="PageBy{TEntity}(QueryBuilder{TEntity},IPagedCollectionView)"/> in sequence.
        /// </summary>
        /// <typeparam name="TEntity">The generic type of the entity</typeparam>
        /// <param name="query">The query to update</param>
        /// <param name="collectionView">The collection view to pass to each method</param>
        /// <returns>An updated query</returns>
        public static QueryBuilder <TEntity> SortAndPageBy <TEntity>(this QueryBuilder <TEntity> query, ICollectionView collectionView) where TEntity : Entity
        {
            IPagedCollectionView pagedCollectionView = collectionView as IPagedCollectionView;

            if (pagedCollectionView == null)
            {
                throw new ArgumentException(Resources.MustImplementIpcv, "collectionView");
            }

            query = CollectionViewExtensions.SortBy(query, collectionView);
            query = CollectionViewExtensions.PageBy(query, pagedCollectionView);
            return(query);
        }
 /// <summary>
 /// Pages the query using the page size and index of the specified <paramref name="collectionView"/>.
 /// </summary>
 /// <remarks>
 /// The paged query will request the total item count if it is not already known to the specified
 /// <paramref name="collectionView"/>.
 /// </remarks>
 /// <typeparam name="TEntity">The generic type of the entity</typeparam>
 /// <param name="query">The query to page</param>
 /// <param name="collectionView">The view containing the paging information</param>
 /// <returns>A query paged according to the specified <paramref name="collectionView"/></returns>
 public static QueryBuilder <TEntity> PageBy <TEntity>(this QueryBuilder <TEntity> query, IPagedCollectionView collectionView) where TEntity : Entity
 {
     if (collectionView.TotalItemCount == -1)
     {
         query.RequestTotalItemCount = true;
     }
     if (collectionView.PageSize > 0)
     {
         query = query.Skip(collectionView.PageIndex * collectionView.PageSize);
         query = query.Take(collectionView.PageSize);
     }
     return(query);
 }
 /// <summary>
 /// Pages the query using the page size and index of the specified <paramref name="collectionView"/>.
 /// </summary>
 /// <remarks>
 /// The paged query will request the total item count if it is not already known to the specified
 /// <paramref name="collectionView"/>.
 /// </remarks>
 /// <typeparam name="TEntity">The generic type of the entity</typeparam>
 /// <param name="query">The query to page</param>
 /// <param name="collectionView">The view containing the paging information</param>
 /// <returns>A query paged according to the specified <paramref name="collectionView"/></returns>
 public static EntityQuery <TEntity> PageBy <TEntity>(this EntityQuery <TEntity> query, IPagedCollectionView collectionView) where TEntity : Entity
 {
     return(CollectionViewExtensions.PageBy(new QueryBuilder <TEntity>(), collectionView).ApplyTo(query));
 }