Пример #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; }
        }
Пример #2
0
 public async Task Commit()
 {
     try
     {
         // For some odd reasons, current LiteDB version does not support transaction
         using (LiteRepository _liteRepo = new LiteRepository(LiteDBLocation))
         {
             if (ToSave.Any() || ToModify.Any())
             {
                 IList <T> _combinedList = ToSave.Concat(ToModify).ToList();
                 _liteRepo.Upsert <T>(_combinedList, CollectionName);
             }
             if (ToRemove.Any())
             {
                 _liteRepo.Delete <T>(Query.Where("_id", id => ToRemove.Contains(id)), CollectionName);
             }
         }
         await Task.Run(() =>
         {
             ToSave.Clear();
             ToModify.Clear();
             ToRemove.Clear();
         });
     }
     catch (Exception ex)
     { throw ex; }
 }