예제 #1
0
 /// <summary>
 /// Adds a foreign key with a single column
 /// </summary>
 /// <param name="databaseColumn">The database column.</param>
 /// <param name="foreignKeyName">Name of the foreign key.</param>
 /// <param name="foreignTableName">Name of the foreign table.</param>
 /// <returns></returns>
 public static DatabaseColumn AddForeignKey(this DatabaseColumn databaseColumn,
                                            string foreignKeyName,
                                            string foreignTableName)
 {
     return(AddForeignKey(databaseColumn, foreignKeyName, foreignTableName, null));
 }
예제 #2
0
        /// <summary>
        /// Adds the column.
        /// </summary>
        /// <param name="databaseConstraint">The database constraint.</param>
        /// <param name="databaseColumn">The database column.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">databaseConstraint</exception>
        public static DatabaseConstraint AddColumn(this DatabaseConstraint databaseConstraint, DatabaseColumn databaseColumn)
        {
            if (databaseConstraint == null)
            {
                throw new ArgumentNullException("databaseConstraint");
            }
            if (databaseColumn == null)
            {
                throw new ArgumentNullException("databaseColumn");
            }
            if (databaseColumn.TableName != databaseConstraint.TableName)
            {
                throw new InvalidOperationException("Constraint and column must belong to same table");
            }

            databaseConstraint.Columns.Add(databaseColumn.Name);
            switch (databaseConstraint.ConstraintType)
            {
            case ConstraintType.ForeignKey:
                databaseColumn.IsForeignKey        = true;
                databaseColumn.ForeignKeyTableName = databaseConstraint.RefersToTable;
                break;

            case ConstraintType.PrimaryKey:
                databaseColumn.IsPrimaryKey = true;
                break;

            case ConstraintType.UniqueKey:
                databaseColumn.IsUniqueKey = true;
                break;
            }

            return(databaseConstraint);
        }
예제 #3
0
 /// <summary>
 /// Adds a foreign key with a single column (without a name)
 /// </summary>
 /// <param name="databaseColumn">The database column.</param>
 /// <param name="foreignTableName">Name of the foreign table.</param>
 /// <returns></returns>
 public static DatabaseColumn AddForeignKey(this DatabaseColumn databaseColumn, string foreignTableName)
 {
     return(databaseColumn.AddForeignKey(null, foreignTableName));
 }
예제 #4
0
 /// <summary>
 /// Makes this column a unique key.
 /// </summary>
 /// <param name="databaseColumn">The database column.</param>
 /// <returns></returns>
 public static DatabaseColumn AddUniqueKey(this DatabaseColumn databaseColumn)
 {
     return(databaseColumn.AddUniqueKey(null));
 }
예제 #5
0
 /// <summary>
 /// Makes this column the primary key (or part of a composite key)
 /// </summary>
 /// <param name="databaseColumn">The database column.</param>
 /// <returns></returns>
 public static DatabaseColumn AddPrimaryKey(this DatabaseColumn databaseColumn)
 {
     return(databaseColumn.AddPrimaryKey(null));
 }