示例#1
0
        public async void Reload()
        {
            if (IsLoading)
            {
                return;
            }

            data.Clear();
            IsLoading = true;
            OnUpdated();

            try {
                var queryTask = query.Skip(data.Count).Take(batchSize).ToListAsync();
                var countTask = query.CountAsync();
                await Task.WhenAll(queryTask, countTask);

                data.AddRange(queryTask.Result);

                var count = countTask.Result;
                HasMore = data.Count < count;
            } finally {
                IsLoading = false;
                OnUpdated();
            }
        }
示例#2
0
        private async Task <int> CountReady(Expression <Func <T, bool> > filter = null,
                                            bool includeDeleted = false)
        {
            AsyncTableQuery <T> tableQuery = _mainContext.GetCurrentContext().Table <T>();

            if (!includeDeleted)
            {
                tableQuery = tableQuery.Where(q => q.IsDeleted.Equals(includeDeleted));
            }

            if (filter != null)
            {
                tableQuery = tableQuery.Where(filter);
            }

            return(await tableQuery.CountAsync());
        }
示例#3
0
        /// <summary>
        /// 分页查询,调用此方法前必须进行排序
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="source"></param>
        /// <param name="current"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static async Task <PagedModel <TEntity> > PagingAsync <TEntity>(
            this AsyncTableQuery <TEntity> source,
            int current  = IPagedModel.DefaultCurrent,
            int pageSize = IPagedModel.DefaultPageSize) where TEntity : new()
        {
            var skipCount = (current - 1) * pageSize;
            var total     = await source.CountAsync();

            var dataSource = await source.Skip(skipCount).Take(pageSize).ToListAsync();

            var pagedModel = new PagedModel <TEntity>
            {
                Current    = current,
                PageSize   = pageSize,
                Total      = total,
                DataSource = dataSource,
            };

            return(pagedModel);
        }
示例#4
0
        public async Task TestAsyncTableQueryCountAsync()
        {
            SQLiteAsyncConnection conn = GetAsyncConnection();
            await conn.CreateTableAsync <Customer>();

            await conn.ExecuteAsync("delete from customer");

            // create...
            for (int index = 0; index < 10; index++)
            {
                await conn.InsertAsync(CreateCustomer());
            }

            // load...
            AsyncTableQuery <Customer> query = conn.Table <Customer>();
            var result = await query.CountAsync();

            // check...
            Assert.AreEqual(10, result);
        }
示例#5
0
        public void TestAsyncTableQueryCountAsync()
        {
            SQLiteAsyncConnection conn = GetConnection();

            conn.CreateTableAsync <Customer>().Wait();
            conn.ExecuteAsync("delete from customer").Wait();

            // create...
            for (int index = 0; index < 10; index++)
            {
                conn.InsertAsync(CreateCustomer()).Wait();
            }

            // load...
            AsyncTableQuery <Customer> query = conn.Table <Customer>();
            Task <int> task = query.CountAsync();

            task.Wait();

            // check...
            Assert.AreEqual(10, task.Result);
        }