示例#1
0
 /// <summary>
 /// Truncates database table
 /// </summary>
 /// <param name="resetIdentity">Performs reset identity column</param>
 public virtual void Truncate(bool resetIdentity = false)
 {
     using (var _dataConnection = new NopDataConnection())
     {
         _dataConnection.GetTable <TEntity>().Truncate(resetIdentity);
     }
 }
示例#2
0
        /// <summary>
        /// Loads the original copy of the entity
        /// </summary>
        /// <typeparam name="TEntity">Entity type</typeparam>
        /// <param name="entity">Entity</param>
        /// <returns>Copy of the passed entity</returns>
        public virtual TEntity LoadOriginalCopy <TEntity>(TEntity entity) where TEntity : BaseEntity
        {
            using (var currentConnection = new NopDataConnection())
            {
                var entities = currentConnection.GetTable <TEntity>();

                return(entities.FirstOrDefault(e => e.Id == Convert.ToInt32(entity.Id)));
            }
        }
示例#3
0
        /// <summary>
        /// Get the current identity value
        /// </summary>
        /// <typeparam name="T">Entity</typeparam>
        /// <returns>Integer identity; null if cannot get the result</returns>
        public virtual int?GetTableIdent <T>() where T : BaseEntity
        {
            using (var currentConnection = new NopDataConnection())
            {
                var tableName = currentConnection.GetTable <T>().TableName;

                var result = currentConnection.Query <decimal?>($"SELECT IDENT_CURRENT('[{tableName}]') as Value")
                             .FirstOrDefault();

                return(result.HasValue ? Convert.ToInt32(result) : 1);
            }
        }
示例#4
0
        /// <summary>
        /// Set table identity (is supported)
        /// </summary>
        /// <typeparam name="T">Entity</typeparam>
        /// <param name="ident">Identity value</param>
        public virtual void SetTableIdent <T>(int ident) where T : BaseEntity
        {
            using (var currentConnection = new NopDataConnection())
            {
                var currentIdent = GetTableIdent <T>();
                if (!currentIdent.HasValue || ident <= currentIdent.Value)
                {
                    return;
                }

                var tableName = currentConnection.GetTable <T>().TableName;

                currentConnection.Execute($"DBCC CHECKIDENT([{tableName}], RESEED, {ident})");
            }
        }