Exemplo n.º 1
0
        public static ICreateTableColumnOptionOrWithColumnSyntax WithColumnForForeignKeyTo <TEntity>(
            this ICreateTableWithColumnSyntax tableWithColumnSyntax, string columnName = null, bool nullable = false)
            where TEntity : class, IEntity
        {
            var defaultColumnName = ColumnName.ForeignKeyTo <TEntity>();
            var columnDefinition  = tableWithColumnSyntax.WithColumn(columnName ?? defaultColumnName).AsInt32();

            return(nullable
                ? columnDefinition.Nullable()
                : columnDefinition.NotNullable());
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
0
        public static ICreateForeignKeyCascadeSyntax BetweenEntities <TForeignEntity, TPrimaryEntity>(this ICreateForeignKeyFromTableSyntax root, string foreignColumnName = null)
            where TForeignEntity : class, IEntity
            where TPrimaryEntity : class, IEntity
        {
            var foreignTableName = TableName.ForEntity <TForeignEntity>();

            foreignColumnName = foreignColumnName ?? ColumnName.ForeignKeyTo <TPrimaryEntity>();

            var primaryTableName  = TableName.ForEntity <TPrimaryEntity>();
            var primaryColumnName = ColumnName.PrimaryKey;

            return(root
                   .FromTable(foreignTableName).ForeignColumn(foreignColumnName)
                   .ToTable(primaryTableName).PrimaryColumn(primaryColumnName));
        }