예제 #1
0
        public async Task<T> Save(T entity)
        {
            entity.Id = Guid.NewGuid();

            await _context.Collection.InsertOneAsync(_session?.Handle, entity);

            var repository = new StorageEntityRepository<T>(this, entity);

            entity.Storage = this;

            return entity;
        }
예제 #2
0
        public async Task<T?> Pick(Expression<Func<T, bool>> expression)
        {
            var result = await _context.Collection.Find(_session?.Handle, expression)
                .FirstOrDefaultAsync();

            if (result is null) return null;

            var repository = new StorageEntityRepository<T>(this, result);
            result.Storage = this;

            return result;
        }
예제 #3
0
        public async Task<IEnumerable<T>> PickMany(Expression<Func<T, bool>> expression)
        {
            var result = await _context.Collection.Find(_session?.Handle, expression)
                .ToListAsync();

            result.ForEach(e =>
            {
                var repository = new StorageEntityRepository<T>(this, e);
                e.Storage = this;
            });

            return result;
        }
예제 #4
0
        public async Task<IEnumerable<T>> PickMany(params Guid[] ids)
        {
            var result = await _context.Collection.Find(_session?.Handle, StorageUtils.BuildIdsFilter<T>(ids))
                .ToListAsync();

            result.ForEach(e =>
            {
                var repository = new StorageEntityRepository<T>(this, e);
                e.Storage = this;
            });

            return result;
        }
예제 #5
0
        public async Task<T?> Pick(Guid id)
        {
            var filter = StorageUtils.BuildIdFilter<T>(id);

            var result = await _context.Collection.Find(_session?.Handle, StorageUtils.BuildIdFilter<T>(id))
                .FirstOrDefaultAsync();

            if (result is null) return null;

            var repository = new StorageEntityRepository<T>(this, result);
            result.Storage = this;

            return result;
        }