Example #1
0
        /// <summary>
        /// 修改列名。
        /// </summary>
        /// <typeparam name="TEntity">实体类型。</typeparam>
        /// <param name="name">原名称(全名包含IX_)。</param>
        /// <param name="columns">新列名表达式。</param>
        /// <returns>返回迁移实例。</returns>
        public virtual OperationBuilder <RenameIndexOperation> RenameIndex <TEntity>(
            string name,
            Expression <Func <TEntity, object> > columns)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(columns, nameof(columns));

            var operation = new RenameIndexOperation
            {
                Table = typeof(TEntity).GetTableName(),
                Name  = name,
            };

            operation.NewName = OperationHelper.GetName(NameType.Index, operation.Table, columns.GetPropertyNames());
            Operations.Add(operation);

            return(new OperationBuilder <RenameIndexOperation>(operation));
        }
Example #2
0
        /// <summary>
        /// 新建索引。
        /// </summary>
        /// <param name="table">表格名称。</param>
        /// <param name="columns">字段列表。</param>
        /// <param name="unique">是否唯一。</param>
        /// <param name="clustered">是否聚合。</param>
        /// <returns>返回迁移实例。</returns>
        public virtual OperationBuilder <CreateIndexOperation> CreateIndex(
            string table,
            string[] columns,
            bool unique    = false,
            bool clustered = false)
        {
            Check.NotNull(columns, nameof(columns));

            var operation = new CreateIndexOperation
            {
                Table       = table,
                Columns     = columns,
                IsUnique    = unique,
                IsClustered = clustered
            };

            operation.Name = OperationHelper.GetName(NameType.Index, operation.Table, operation.Columns);
            Operations.Add(operation);

            return(new OperationBuilder <CreateIndexOperation>(operation));
        }