コード例 #1
0
        public async Task <IEnumerable <Job> > QueryFor(JobQuery query)
        {
            var mongoQuery = _jobs.Find(query.BuildFilters());

            if (query.Limit.HasValue)
            {
                mongoQuery = mongoQuery.Limit(query.Limit.Value);
            }

            if (query.Skip.HasValue)
            {
                mongoQuery = mongoQuery.Skip(query.Skip.Value);
            }

            if (!string.IsNullOrWhiteSpace(query.AdhocSort))
            {
                BsonDocument bsonDocumentSort;
                try
                {
                    bsonDocumentSort = BsonSerializer.Deserialize <BsonDocument>(query.AdhocSort);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException($"Invalid adhocSort ({query.AdhocSort})", ex);
                }
                mongoQuery = mongoQuery.Sort(bsonDocumentSort);
            }

            return(await mongoQuery.ToListAsync().ConfigureAwait(false));
        }
コード例 #2
0
        public async Task <IEnumerable <Job> > QueryFor(JobQuery query)
        {
            var mongoQuery = _jobs.Find(query.BuildFilters());

            if (query.Limit.HasValue)
            {
                mongoQuery = mongoQuery.Limit(query.Limit.Value);
            }

            return(await mongoQuery.ToListAsync().ConfigureAwait(false));
        }
コード例 #3
0
 public async Task <long> QueryCount(JobQuery query)
 {
     return(await _jobs.Find(query.BuildFilters()).CountAsync().ConfigureAwait(false));
 }