/// <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)); }
/// <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); }
/// <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)); }
/// <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)); }
/// <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)); }