Exemplo n.º 1
0
        public async Task <PaginationQueryResult <Beatmap> > SearchBeatmapByOptions(
            string searchText,
            BeatmapOrderOptions beatmapOrderOptions,
            int page,
            int countPerPage)
        {
            var sqliteParameters = new List <SqliteParameter>();
            var command          = " SELECT * FROM Beatmaps WHERE ";
            var keywordSql       = GetKeywordQueryAndArgs(searchText, ref sqliteParameters);
            var sort             = GetOrderAndTakeQueryAndArgs(beatmapOrderOptions, page, countPerPage);
            var sw = Stopwatch.StartNew();

            try
            {
                var sql        = command + keywordSql;
                var totalCount = await Beatmaps
                                 .FromSqlRaw(sql, sqliteParameters.Cast <object>().ToArray())
                                 .CountAsync();

                var s        = sql + sort;
                var beatmaps = await Beatmaps
                               .FromSqlRaw(s, sqliteParameters.Cast <object>().ToArray())
                               .ToListAsync();

                return(new PaginationQueryResult <Beatmap>(beatmaps, totalCount));
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Error while calling SearchBeatmapByOptions().");
                throw;
            }
            finally
            {
                Logger.Debug("查询花费: {0}", sw.ElapsedMilliseconds);
                sw.Stop();
            }
        }