Beispiel #1
0
        public static IAlterTableColumnOptionOrAddColumnOrAlterColumnSyntax AddColumnForForeignKeyTo <TEntity>(
            this IAlterTableAddColumnOrAlterColumnOrSchemaOrDescriptionSyntax tableWithColumnSyntax, string columnName = null, bool nullable = false)
            where TEntity : class, IEntity
        {
            var defaultColumnName = ColumnName.ForeignKeyTo <TEntity>();
            var columnDefinition  = tableWithColumnSyntax.AddColumn(columnName ?? defaultColumnName).AsInt32();

            return(nullable
                ? columnDefinition.Nullable()
                : columnDefinition.NotNullable());
        }
Beispiel #2
0
        public static IAlterTableAddColumnOrAlterColumnOrSchemaOrDescriptionSyntax IntForeignKeyIndexed(this IAlterTableAddColumnOrAlterColumnOrSchemaOrDescriptionSyntax self,
                                                                                                        string name, string foreignTable, bool isNullable, bool isPK)
        {
            IAlterTableColumnOptionOrAddColumnOrAlterColumnSyntax col;

            if (isNullable)
            {
                col = self.AddColumn(name).AsInt32().Nullable().ForeignKey(foreignTable, "id");
            }
            else
            {
                col = self.AddColumn(name).AsInt32().NotNullable().ForeignKey(foreignTable, "id");
            }

            if (isPK)
            {
                col.PrimaryKey();
            }
            else
            {
                col.Indexed();
            }

            return(self);
        }
Beispiel #3
0
        public static IAlterTableAddColumnOrAlterColumnOrSchemaOrDescriptionSyntax IntForeignKey(this IAlterTableAddColumnOrAlterColumnOrSchemaOrDescriptionSyntax self,
                                                                                                 string name, string foreignTable, bool isNullable, bool isUnique = false, bool onDeleteCascade = false)
        {
            IAlterTableColumnOptionOrAddColumnOrAlterColumnSyntax col;

            var rule = onDeleteCascade ? System.Data.Rule.Cascade : System.Data.Rule.None;

            if (isUnique)
            {
                col = self.AddColumn(name).AsInt32().ForeignKey(foreignTable, "Id").OnDelete(rule).Unique();
            }
            else
            {
                col = self.AddColumn(name).AsInt32().ForeignKey(foreignTable, "Id").OnDelete(rule).Indexed();
            }

            if (isNullable)
            {
                col.Nullable();
            }
            else
            {
                col.NotNullable();
            }

            return(self);
        }