public async Task <IActionResult> IndexAsync(CancellationToken cancellationToken = default) { await Context.Database.EnsureCreatedAsync(cancellationToken); await Context.GenerateDataAsync(cancellationToken); int count = await Context.Customers.AsNoTracking().CountAsyncEF(cancellationToken); int futureCount = Context.Customers.AsNoTracking().Future().Count(); _logger.LogInformation($"Future Customer Count: {futureCount}"); QueryFutureValue <Customer> futureFirstCustomer = Context.Customers.AsNoTracking() .Where(x => x.IsActive).DeferredFirstOrDefault().FutureValue(); QueryFutureValue <int> futureCustomerCount = Context.Customers.AsNoTracking() .Where(x => x.IsActive).DeferredCount().FutureValue(); Customer firstCustomer = futureFirstCustomer.Value; int countCustomer = futureCustomerCount.Value; QueryFutureValue <int> futureMaxPrice = Context.Products.AsNoTracking().DeferredMax(x => x.Prices).FutureValue <int>(); QueryFutureValue <int> futureMinPrice = Context.Products.AsNoTracking().DeferredMin(x => x.Prices).FutureValue <int>(); int maxPrice = futureMaxPrice.Value; int minPrice = futureMinPrice.Value; _logger.LogInformation($"Max Price: {maxPrice}"); _logger.LogInformation($"Min Price: {minPrice}"); IEnumerable <Product> resultPeopleActive = await Context.Products.AsNoTracking() .Where(c => c.IsActive) .ToListAsyncEF(cancellationToken) ; IEnumerable <Product> resultPeopleNonActive = await Context.Products.AsNoTracking() .Where(c => !c.IsActive) .ToListAsyncEF(cancellationToken) ; QueryFutureEnumerable <Product> resultPeopleActiveWithFuture = Context.Products.AsNoTracking() .Where(c => c.IsActive) .Future() ; QueryFutureEnumerable <Product> resultPeopleNonActiveWithFuture = Context.Products.AsNoTracking() .Where(c => !c.IsActive) .Future() ; IEnumerable <Product> resultPeopleActiveWith = await resultPeopleActiveWithFuture.ToListAsync(cancellationToken); IEnumerable <Product> resultPeopleNonActiveWith = await resultPeopleNonActiveWithFuture.ToListAsync(cancellationToken); if (resultPeopleActive == resultPeopleActiveWith && resultPeopleNonActive == resultPeopleNonActiveWith) { _logger.LogInformation("Results are the same .. !!!!"); } IQueryable <Product> query = Context.Products.AsNoTracking().Where(c => c.IsActive); var pagedQueryable = await query .OrderBy(p => p.ProductId) .Skip(1).Take(4) .Select(p => new { TotalAsync = query.CountAsyncEF(cancellationToken), Item = p }) .ToListAsyncEF(cancellationToken) ; int totalQuery = await pagedQueryable.FirstOrDefault().TotalAsync; IEnumerable <Product> items = pagedQueryable.Select(p => p.Item).ToList(); var page = await query .OrderBy(p => p.Name) .Select(p => p) .Skip(1).Take(4) .GroupBy(p => new { TotalAsync = query.CountAsyncEF(cancellationToken) }) .FirstOrDefaultAsyncEF(cancellationToken) ; int total = await page.Key.TotalAsync; IEnumerable <Product> people = page.Select(p => p); IEnumerable <ProductResult> results = await query .OrderBy(p => p.Name) .Skip(1).Take(4) .Select(p => new ProductResult(p, query.Count())) .ToListAsyncEF(cancellationToken) ; int totalCount = results.FirstOrDefault().TotalCount; IEnumerable <ProductResult> peopleResult = results.Select(p => p).ToList(); IQueryable <Product> queryAsQueryable = Context.Products.AsNoTracking().AsQueryable(); Task <List <Product> > resultsTask = query.OrderBy(p => p.ProductId).Skip(1).Take(4).ToListAsyncEF(cancellationToken); Task <int> countTask = query.CountAsyncEF(cancellationToken); await Task.WhenAll(resultsTask, countTask); int TotaslCount = await countTask; IEnumerable <Product> Data = await resultsTask; IQueryable <Customer> baseQuery = Context.Customers.AsNoTracking().Where(c => c.IsActive); var customerResult = await baseQuery .Select(e => new { Total = Sql.Ext.Count().Over().ToValue(), Item = e }) .Skip(1).Take(4) .ToLinqToDB() .ToListAsyncEF(cancellationToken) ; int totalCustomers = customerResult.First().Total; IEnumerable <Customer> customersData = customerResult.Select(c => c.Item).ToList(); QueryFutureEnumerable <Customer> getTotalCountFuture = baseQuery.Future(); QueryFutureEnumerable <Customer> getPageFuture = baseQuery.Skip(1).Take(4).Future(); int getTotalCountResult = getTotalCountFuture.Count(); IEnumerable <Customer> getPageResult = await getPageFuture.ToListAsync(cancellationToken); return(View()); }
public async Task <IActionResult> IndexAsync(CancellationToken cancellationToken = default) { await Context.Database.EnsureCreatedAsync(cancellationToken); await Context.GenerateDataAsync(cancellationToken); int count = await Context.Customers.CountAsync(cancellationToken); int futureCount = Context.Customers.Future().Count(); _logger.LogInformation($"Future Customer Count: {futureCount}"); QueryFutureValue <int> futureMaxPrice = Context.Products.DeferredMax(x => x.Prices).FutureValue <int>(); QueryFutureValue <int> futureMinPrice = Context.Products.DeferredMin(x => x.Prices).FutureValue <int>(); int maxPrice = futureMaxPrice.Value; int minPrice = futureMinPrice.Value; _logger.LogInformation($"Max Price: {maxPrice}"); _logger.LogInformation($"Min Price: {minPrice}"); IEnumerable <Product> resultPeopleActive = await Context.Products.AsNoTracking() .Where(c => c.IsActive) .ToListAsync(cancellationToken) ; IEnumerable <Product> resultPeopleNonActive = await Context.Products.AsNoTracking() .Where(c => !c.IsActive) .ToListAsync(cancellationToken) ; QueryFutureEnumerable <Product> resultPeopleActiveWithFuture = Context.Products.AsNoTracking() .Where(c => c.IsActive) .Future() ; QueryFutureEnumerable <Product> resultPeopleNonActiveWithFuture = Context.Products.AsNoTracking() .Where(c => !c.IsActive) .Future() ; IEnumerable <Product> resultPeopleActiveWith = await resultPeopleActiveWithFuture.ToListAsync(cancellationToken); IEnumerable <Product> resultPeopleNonActiveWith = await resultPeopleNonActiveWithFuture.ToListAsync(cancellationToken); if (resultPeopleActive == resultPeopleActiveWith && resultPeopleNonActive == resultPeopleNonActiveWith) { _logger.LogInformation("Results are the same .. !!!!"); } //◘◘◘◘ Paging ◘◘◘◘ IQueryable <Product> query = Context.Products.Where(c => c.IsActive); var page = await query.OrderBy(p => p.Name) .Select(p => p.Name) .Skip(1) .Take(4) .GroupBy(p => new { Total = query.Count() }) .FirstOrDefaultAsync(cancellationToken); int total = page.Key.Total; var people = page.Select(p => p); IQueryable <Customer> baseQuery = Context.Customers.Where(c => c.IsActive); QueryFutureEnumerable <Customer> getTotalCountFuture = baseQuery.Future(); QueryFutureEnumerable <Customer> getPageFuture = baseQuery.Skip(1).Take(4).Future(); int getTotalCountResult = getTotalCountFuture.Count(); IEnumerable <Customer> getPageResult = await getPageFuture.ToListAsync(cancellationToken); return(View()); }
public async Task <IActionResult> IndexAsync(CancellationToken cancellationToken = default) { await Context.Database.EnsureCreatedAsync(cancellationToken); await Context.GenerateDataAsync(cancellationToken); int count = await Context.Customers.CountAsync(cancellationToken); int futureCount = Context.Customers.Future().Count(); Console.WriteLine("Future Customer Count: {0}", futureCount); QueryFutureValue <int> futureMaxPrice = Context.Products.DeferredMax(x => x.Prices).FutureValue <int>(); QueryFutureValue <int> futureMinPrice = Context.Products.DeferredMin(x => x.Prices).FutureValue <int>(); int maxPrice = futureMaxPrice.Value; int minPrice = futureMinPrice.Value; Console.WriteLine("Max Price: {0}", maxPrice); Console.WriteLine("Min Price: {0}", minPrice); IEnumerable <Product> resultPeopleActive = await Context.Products.AsNoTracking() .Where(c => c.IsActive) .ToListAsync(cancellationToken) ; IEnumerable <Product> resultPeopleNonActive = await Context.Products.AsNoTracking() .Where(c => !c.IsActive) .ToListAsync(cancellationToken) ; QueryFutureEnumerable <Product> resultPeopleActiveWithFuture = Context.Products.AsNoTracking() .Where(c => c.IsActive) .Future() ; QueryFutureEnumerable <Product> resultPeopleNonActiveWithFuture = Context.Products.AsNoTracking() .Where(c => !c.IsActive) .Future() ; IEnumerable <Product> resultPeopleActiveWith = await resultPeopleActiveWithFuture.ToListAsync(cancellationToken); IEnumerable <Product> resultPeopleNonActiveWith = await resultPeopleNonActiveWithFuture.ToListAsync(cancellationToken); if (resultPeopleActive == resultPeopleActiveWith && resultPeopleNonActive == resultPeopleNonActiveWith) { Console.WriteLine("Results are the same .. !!!!"); } IQueryable <Customer> baseQuery = Context.Customers.Where(c => c.IsActive); QueryFutureEnumerable <Customer> getTotalCountFuture = baseQuery.Future(); QueryFutureEnumerable <Customer> getPageFuture = baseQuery.Skip(1).Take(4).Future(); int getTotalCountResult = getTotalCountFuture.Count(); IEnumerable <Customer> getPageResult = await getPageFuture.ToListAsync(cancellationToken); return(View()); }