Пример #1
0
        /// <summary>Commit changes made to the collection.</summary>
        async Task ICollectionRef <T> .Commit()
        {
            try
            {
                using LiteRepository _liteRepo = new LiteRepository(RefConfig.Location);
                if (ToSave.Any() || ToModify.Any())
                {
                    IList <T> _combinedList = ToSave.Concat(ToModify).ToList();
                    _liteRepo.Upsert <T>(_combinedList, RefConfig.Collection);
                }
                if (ToRemove.Any())
                {
                    BsonValue[] _bsonValues = ToRemove.Select(_id => new BsonValue(_id)).ToArray();
                    _liteRepo.DeleteMany <T>(Query.In("_id", _bsonValues), RefConfig.Collection);
                }

                await Task.Run(() =>
                {
                    ToSave.Clear();
                    ToModify.Clear();
                    ToRemove.Clear();
                });
            }
            catch (Exception ex)
            { throw ex; }
        }