public IQueryResult <TEntity, TBase> Execute()
        {
            IEnumerable <TEntity> data = this.ToArray();

            return(new QueryResult(EntitySet, data, QueryTotalCount.GetValueOrDefault(false) ? EntitySet.TotalCount : default(long?)));
        }
        public override void ExecuteAsync(Action <IQueryResult <TEntity, TBase> > callback = null)
        {
            var dispatcher = Deployment.Dispatcher;

            // framework implementation
            if (EntitySet is EntitySet <TBase> )
            {
                ((EntitySet <TBase>) EntitySet).LoadAsync
                (
                    ClientInfo,
                    Query,
                    delegate(IEnumerable <TBase> data, long?totalCount, Exception exception)
                {
                    if (callback != null)
                    {
                        QueryResult result;
                        if (ReferenceEquals(null, exception))
                        {
                            result = new QueryResult(EntitySet, data.OfType <TEntity>(), QueryTotalCount.GetValueOrDefault(false) ? totalCount : default(long?));
                        }
                        else
                        {
                            result = new QueryResult(exception);
                        }

                        // call back on calling thread
                        dispatcher.BeginInvoke(delegate
                        {
                            callback(result);
                        });
                    }
                }
                );
            }
            else // client implementation e.g. mock-up
            {
                if (callback != null)
                {
                    var result = new QueryResult(EntitySet, EntitySet.OfType <TEntity>(), EntitySet.TotalCount);

                    // call back on calling thread
                    dispatcher.BeginInvoke(delegate
                    {
                        callback(result);
                    });
                }
            }
        }