Example #1
0
        internal void Save(IDbConnection db)
        {
            if (!_deniesToRemove.IsEmpty)
            {
                var  idsToRemove = new StringBuilder();
                var  firstRun    = true;
                Deny denyToRemove;
                while (_deniesToRemove.TryPop(out denyToRemove))
                {
                    if (firstRun)
                    {
                        firstRun = false;
                    }
                    else
                    {
                        idsToRemove.Append(',');
                    }
                    idsToRemove.Append(denyToRemove.Id);
                }

                db.BulkDelete <PlayerDenyDto>(statement => statement
                                              .Where($"{nameof(PlayerDenyDto.Id):C} IN ({idsToRemove})"));
            }

            foreach (var deny in _denies.Values.Where(deny => !deny.ExistsInDatabase))
            {
                db.Insert(new PlayerDenyDto
                {
                    Id           = deny.Id,
                    PlayerId     = (int)Player.Account.Id,
                    DenyPlayerId = (int)deny.DenyId
                });
                deny.ExistsInDatabase = true;
            }
        }
 protected virtual void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         connection.BulkDelete <Person>();
         disposedValue = true;
     }
 }
Example #3
0
        internal void Save(IDbConnection db)
        {
            if (!_licensesToRemove.IsEmpty)
            {
                var     idsToRemove = new StringBuilder();
                var     firstRun    = true;
                License licenseToRemove;
                while (_licensesToRemove.TryPop(out licenseToRemove))
                {
                    if (firstRun)
                    {
                        firstRun = false;
                    }
                    else
                    {
                        idsToRemove.Append(',');
                    }
                    idsToRemove.Append(licenseToRemove.Id);
                }

                db.BulkDelete <PlayerLicenseDto>(statement => statement
                                                 .Where($"{nameof(PlayerLicenseDto.Id):C} IN ({idsToRemove})"));
            }

            foreach (var license in this)
            {
                if (!license.ExistsInDatabase)
                {
                    db.Insert(new PlayerLicenseDto
                    {
                        Id                 = license.Id,
                        PlayerId           = (int)_player.Account.Id,
                        License            = (byte)license.ItemLicense,
                        FirstCompletedDate = license.FirstCompletedDate.ToUnixTimeSeconds(),
                        CompletedCount     = license.TimesCompleted
                    });
                    license.ExistsInDatabase = true;
                }
                else
                {
                    if (!license.NeedsToSave)
                    {
                        continue;
                    }

                    var mapping = OrmConfiguration
                                  .GetDefaultEntityMapping <PlayerLicenseDto>()
                                  .Clone()
                                  .UpdatePropertiesExcluding(prop => prop.IsExcludedFromUpdates = true,
                                                             nameof(PlayerLicenseDto.CompletedCount));
                    db.Update(new PlayerLicenseDto
                    {
                        CompletedCount = license.TimesCompleted
                    }, statement => statement.WithEntityMappingOverride(mapping));
                    license.NeedsToSave = false;
                }
            }
        }
Example #4
0
        public static int BulkDelete <TEntity>(IDbConnection db,
                                               Action <IConditionalBulkSqlStatementOptionsBuilder <TEntity> > statementOptions = null)
        {
            // using (Sync.Lock())
            {
                try
                {
                    return(db.BulkDelete(statementOptions));
                }
                catch (Exception e)
                {
                    Logger.Error($"DBError, {e}");
                }

                return(-1);
            }
        }
Example #5
0
        internal void Save(IDbConnection db)
        {
            if (!_itemsToDelete.IsEmpty)
            {
                var        idsToRemove = new StringBuilder();
                var        firstRun    = true;
                PlayerItem itemToDelete;
                while (_itemsToDelete.TryPop(out itemToDelete))
                {
                    if (firstRun)
                    {
                        firstRun = false;
                    }
                    else
                    {
                        idsToRemove.Append(',');
                    }
                    idsToRemove.Append(itemToDelete.Id);
                }

                db.BulkDelete <PlayerItemDto>(statement => statement
                                              .Where($"{nameof(PlayerItemDto.Id):C} IN ({idsToRemove})"));
            }

            foreach (var item in _items.Values)
            {
                if (!item.ExistsInDatabase)
                {
                    db.Insert(new PlayerItemDto
                    {
                        Id             = (int)item.Id,
                        PlayerId       = (int)Player.Account.Id,
                        ShopItemInfoId = item.GetShopItemInfo().Id,
                        ShopPriceId    = item.GetShopItemInfo().PriceGroup.GetPrice(item.PeriodType, item.Period).Id,
                        Effect         = item.Effect,
                        Color          = item.Color,
                        PurchaseDate   = item.PurchaseDate.ToUnixTimeSeconds(),
                        Durability     = item.Durability,
                        Count          = (int)item.Count
                    });
                    item.ExistsInDatabase = true;
                }
                else
                {
                    if (!item.NeedsToSave)
                    {
                        continue;
                    }

                    db.Update(new PlayerItemDto
                    {
                        Id             = (int)item.Id,
                        PlayerId       = (int)Player.Account.Id,
                        ShopItemInfoId = item.GetShopItemInfo().Id,
                        ShopPriceId    = item.GetShopPrice().Id,
                        Effect         = item.Effect,
                        Color          = item.Color,
                        PurchaseDate   = item.PurchaseDate.ToUnixTimeSeconds(),
                        Durability     = item.Durability,
                        Count          = (int)item.Count
                    });
                    item.NeedsToSave = false;
                }
            }
        }
Example #6
0
        internal void Save(IDbConnection db)
        {
            if (!_charactersToDelete.IsEmpty)
            {
                var idsToRemove = new StringBuilder();
                var firstRun    = true;
                while (_charactersToDelete.TryPop(out var charToDelete))
                {
                    if (firstRun)
                    {
                        firstRun = false;
                    }
                    else
                    {
                        idsToRemove.Append(',');
                    }
                    idsToRemove.Append(charToDelete.Id);
                }

                db.BulkDelete <PlayerCharacterDto>(statement => statement
                                                   .Where($"{nameof(PlayerCharacterDto.Id):C} IN ({idsToRemove})"));
            }

            foreach (var @char in _characters.Values)
            {
                if ([email protected])
                {
                    var charDto = new PlayerCharacterDto
                    {
                        Id         = @char.Id,
                        PlayerId   = (int)Player.Account.Id,
                        Slot       = @char.Slot,
                        Gender     = (byte)@char.Gender,
                        BasicHair  = @char.Hair.Variation,
                        BasicFace  = @char.Face.Variation,
                        BasicShirt = @char.Shirt.Variation,
                        BasicPants = @char.Pants.Variation
                    };
                    SetDtoItems(@char, charDto);
                    db.Insert(charDto);
                    @char.ExistsInDatabase = true;
                }
                else
                {
                    if ([email protected])
                    {
                        continue;
                    }

                    var charDto = new PlayerCharacterDto
                    {
                        Id         = @char.Id,
                        PlayerId   = (int)Player.Account.Id,
                        Slot       = @char.Slot,
                        Gender     = (byte)@char.Gender,
                        BasicHair  = @char.Hair.Variation,
                        BasicFace  = @char.Face.Variation,
                        BasicShirt = @char.Shirt.Variation,
                        BasicPants = @char.Pants.Variation
                    };
                    SetDtoItems(@char, charDto);
                    db.Update(charDto);
                    @char.NeedsToSave = false;
                }
            }
        }
Example #7
0
 /// <summary>
 ///     An IDbConnection extension method to DELETE entities in a database table or a view.
 /// </summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="connection">The connection to act on.</param>
 /// <param name="items">items to delete.</param>
 /// <param name="selectors">The selection of entities to delete.</param>
 /// <returns>A DapperPlusActionSet&lt;T&gt;</returns>
 public static DapperPlusActionSet <T> BulkDelete <T>(this IDbConnection connection, IEnumerable <T> items, params Func <T, object>[] selectors)
 {
     return(connection.BulkDelete(null, items, selectors));
 }
Example #8
0
 /// <summary>
 ///     An IDbConnection extension method to DELETE entities in a database table or a view.
 /// </summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="connection">The connection to act on.</param>
 /// <param name="items">items to delete.</param>
 /// <returns>A DapperPlusActionSet&lt;T&gt;</returns>
 public static DapperPlusActionSet <T> BulkDelete <T>(this IDbConnection connection, params T[] items)
 {
     return(connection.BulkDelete <T>(null, items));
 }
Example #9
0
File: DbUtil.cs Project: zj-work/DZ
        /// <summary>
        /// 批量删除 待测试
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entities"></param>
        /// <returns></returns>
        public int DeleteRange <T>(IEnumerable <T> entities)
        {
            var res = Connection.BulkDelete <T>(entities);

            return(res.Current.Count());
        }
 public void BulkDelete <T>(IEnumerable <T> ts)
 {
     Write();
     connection.BulkDelete <T>(ts);
 }