Esempio n. 1
0
        /// <summary>
        /// 添加唯一键。
        /// </summary>
        /// <param name="columns">列。</param>
        /// <param name="action">添加扩展信息。</param>
        /// <returns>返回迁移构建实例。</returns>
        public virtual CreateTableBuilder <TEntity> UniqueConstraint(
            [NotNull] Expression <Func <TEntity, object> > columns,
            Action <OperationBuilder <AddUniqueConstraintOperation> > action = null)
        {
            Check.NotNull(columns, nameof(columns));

            var operation = new AddUniqueConstraintOperation
            {
                Table   = Operation.Table,
                Columns = columns.GetPropertyNames()
            };

            operation.Name = OperationHelper.GetName(NameType.UniqueKey, operation.Table, operation.Columns);
            Operation.UniqueConstraints.Add(operation);

            action?.Invoke(new OperationBuilder <AddUniqueConstraintOperation>(operation));
            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// 添加主键。
        /// </summary>
        /// <param name="action">添加扩展信息。</param>
        /// <returns>返回迁移构建实例。</returns>
        public virtual CreateTableBuilder <TEntity> PrimaryKey(Action <OperationBuilder <AddPrimaryKeyOperation> > action = null)
        {
            var key = _model.GetEntity(typeof(TEntity)).PrimaryKey;

            if (key == null)
            {
                return(this);
            }

            var operation = new AddPrimaryKeyOperation
            {
                Table   = Operation.Table,
                Columns = key.Properties.Select(p => p.Name).ToArray()
            };

            operation.Name       = OperationHelper.GetName(NameType.PrimaryKey, operation.Table);
            Operation.PrimaryKey = operation;

            action?.Invoke(new OperationBuilder <AddPrimaryKeyOperation>(operation));
            return(this);
        }