Exemplo n.º 1
0
        protected async Task UpdateManyByQuery(MongoQueryBuilder <TEntity, TKey> query)
        {
            if (query.Filter == null)
            {
                query.Where(x => true);
            }

            query.UpdateSet(x => x.UpdateTime, DateTime.UtcNow);

            await _collection.UpdateManyAsync(query.Filter, query.Update);
        }
Exemplo n.º 2
0
        protected virtual async Task <TEntity> GetByQueryFirst(MongoQueryBuilder <TEntity, TKey> query)
        {
            if (query.Filter == null)
            {
                query.Where(x => true);
            }

            var fluent = _collection.Find(query.Filter);

            if (query.Sort != null)
            {
                fluent = fluent.Sort(query.Sort).Skip(query.PropertySkip);
            }

            if (query.Projection != null)
            {
                fluent = fluent.Project <TEntity>(query.Projection);
            }

            return(await fluent.FirstOrDefaultAsync());
        }
Exemplo n.º 3
0
        protected virtual async Task <IEnumerable <TEntity> > GetByQuery(MongoQueryBuilder <TEntity, TKey> query)
        {
            if (query.Filter == null)
            {
                query.Where(x => true);
            }

            var fluent = _collection.Find(query.Filter);

            if (query.Sort != null)
            {
                fluent = fluent.Sort(query.Sort).Skip(query.PropertySkip).Limit(query.PropertyLimit);
            }

            if (query.Projection != null)
            {
                fluent = fluent.Project <TEntity>(query.Projection);
            }

            return(await fluent.ToListAsync());
        }