public async Task <PaginationQueryResult <Beatmap> > GetBeatmapsFromCollection(Collection collection, int page = 0, int countPerPage = 50, BeatmapOrderOptions options = BeatmapOrderOptions.CreateTime) { if (collection.Id == Guid.Empty) { Console.WriteLine("No collection found."); return(new PaginationQueryResult <Beatmap>(new List <Beatmap>(), 0)); } collection = await Collections.FindAsync(collection.Id); if (collection == null) { Console.WriteLine("No collection found."); return(new PaginationQueryResult <Beatmap>(new List <Beatmap>(), 0)); } var relations = Relations .AsNoTracking() .Where(k => k.CollectionId == collection.Id); var beatmaps = relations.Join(Beatmaps, k => k.BeatmapId, k => k.Id, (k, x) => x); var count = await beatmaps.CountAsync(); var enumerable = options switch { BeatmapOrderOptions.UpdateTime => beatmaps.OrderByDescending(k => k.UpdateTime), BeatmapOrderOptions.CreateTime => beatmaps.OrderByDescending(k => k.CreateTime), _ => throw new ArgumentOutOfRangeException(nameof(options), options, null) }; var result = await enumerable .Skip(page *countPerPage) .Take(countPerPage) .ToListAsync(); return(new PaginationQueryResult <Beatmap>(result, count)); }