public static ITransformationProvider AddManyToManyJoiningTable(this ITransformationProvider database, string schema, string lhsTableName, string lhsKey, string rhsTableName, string rhsKey, string joiningTableName)
		{
			string joiningTableWithSchema = TransformationProviderUtility.FormatTableName(schema, joiningTableName);

			string joinLhsKey = Inflector.Singularize(lhsTableName) + "Id";
			string joinRhsKey = Inflector.Singularize(rhsTableName) + "Id";

			database.AddTable(joiningTableWithSchema,
												new Column(joinLhsKey, DbType.Guid, ColumnProperty.NotNull),
												new Column(joinRhsKey, DbType.Guid, ColumnProperty.NotNull));

			string pkName = "PK_" + joiningTableName;

			pkName = ShortenKeyNameToBeSuitableForOracle(pkName);

			database.AddPrimaryKey(pkName, joiningTableWithSchema, joinLhsKey, joinRhsKey);

			string lhsTableNameWithSchema = TransformationProviderUtility.FormatTableName(schema, lhsTableName);
			string rhsTableNameWithSchema = TransformationProviderUtility.FormatTableName(schema, rhsTableName);

			string lhsFkName = TransformationProviderUtility.CreateForeignKeyName(lhsTableName, joiningTableName);
			database.AddForeignKey(lhsFkName, joiningTableWithSchema, joinLhsKey, lhsTableNameWithSchema, lhsKey, ForeignKeyConstraint.NoAction);

			string rhsFkName = TransformationProviderUtility.CreateForeignKeyName(rhsTableName, joiningTableName);
			database.AddForeignKey(rhsFkName, joiningTableWithSchema, joinRhsKey, rhsTableNameWithSchema, rhsKey, ForeignKeyConstraint.NoAction);

			return database;
		}
        public static void AddConstraint(this IQuery query, ObjectName tableName, ConstraintInfo constraintInfo)
        {
            if (constraintInfo.ConstraintType == ConstraintType.PrimaryKey) {
                var columnNames = constraintInfo.ColumnNames;
                if (columnNames.Length > 1)
                    throw new ArgumentException();

                query.AddPrimaryKey(tableName, columnNames[0], constraintInfo.ConstraintName);
            } else if (constraintInfo.ConstraintType == ConstraintType.Unique) {
                query.AddUniqueKey(tableName, constraintInfo.ColumnNames, constraintInfo.ConstraintName);
            } else if (constraintInfo.ConstraintType == ConstraintType.Check) {
                query.AddCheck(tableName, constraintInfo.CheckExpression, constraintInfo.ConstraintName);
            } else if (constraintInfo.ConstraintType == ConstraintType.ForeignKey) {
                query.AddForeignKey(tableName, constraintInfo.ColumnNames, constraintInfo.ForeignTable,
                    constraintInfo.ForeignColumnNames, constraintInfo.OnDelete, constraintInfo.OnUpdate, constraintInfo.ConstraintName);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Adds a primary key constraint to the table with the default name.
 /// </summary>
 public static IAddedPrimaryKey AddPrimaryKey(this IExistingTable table)
 {
     return table.AddPrimaryKey(null);
 }
 public static void AddPrimaryKey(this IQuery query, ObjectName tableName, string columnName, string constraintName)
 {
     query.AddPrimaryKey(tableName, new[] { columnName }, constraintName);
 }
 /// <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);
 }