will be error when I using ToListAsync?

mc 3,441 Reputation points

now I am testing the .net maui android and using sqlite. when I read data in sqlite and click the button quickly. _context.Products.AsNoTracking().OrderByDescending(x => x.Id).Skip(0).Take(pageSize).Where(x => ids.Contains(x.ProductTypeId)).ToListAsync(); it may return Count = 0 but it is wrong and I change it to

await (from p in _context.Products.AsNoTracking()
                              join i in ids
                              on p.ProductTypeId equals i
                              select p).OrderByDescending(x => x.Id).Skip(0).Take(pageSize).ToListAsync();

no matter how fast I click it the result is right. why?

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,584 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 52,576 Reputation points

    In the non working code, you sort, take the first page size entries, then perform a where on this subset. In the working code, you filter from the whole set, than sort and take.