Exemplo n.º 1
0
        public static ICreateTableWithColumnOrSchemaSyntax SmallIntForeignKeyIndexed(this ICreateTableWithColumnOrSchemaSyntax self,
                                                                                     string name, string foreignTable, bool isNullable, bool isPK)
        {
            ICreateTableColumnOptionOrWithColumnSyntax col;

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

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

            return(self);
        }
 public static ICreateTableColumnOptionOrWithColumnSyntax WithIdColumn(this ICreateTableWithColumnOrSchemaSyntax createTable)
 {
     return(createTable.WithColumn("Id")
            .AsInt64()
            .NotNullable()
            .PrimaryKey()
            .Identity());
 }
Exemplo n.º 3
0
        /// <summary>
        /// Ordinary Changeinfo with relations
        /// </summary>
        /// <param name="self"></param>
        /// <returns></returns>
        public static ICreateTableWithColumnOrSchemaSyntax ChangeInfo(this ICreateTableWithColumnOrSchemaSyntax self)
        {
            self.WithColumn("DateCreated").AsDateTime().NotNullable().WithDefaultValue(new SQLServerFunction("getutcdate()"))
            .WithColumn("CreatedByUserId").AsInt32().NotNullable().ForeignKey(Tables.User, "Id").Indexed()
            .WithColumn("LastModified").AsDateTime().NotNullable().WithDefaultValue(new SQLServerFunction("getutcdate()"))
            .WithColumn("LastModifiedByUserId").AsInt32().Nullable().ForeignKey(Tables.User, "Id").Indexed();

            return(self);
        }
Exemplo n.º 4
0
 public static ICreateTableColumnOptionOrWithColumnSyntax WithDefaultColumns(
     this ICreateTableWithColumnOrSchemaSyntax table)
 {
     return(table.WithColumn("Id").AsInt64().PrimaryKey().Identity()
            .WithColumn("CreatedOn").AsDateTime()
            .WithColumn("CreatedBy").AsString().Nullable()
            .WithColumn("ModifiedOn").AsDateTime()
            .WithColumn("ModifiedBy").AsString().Nullable());
 }
Exemplo n.º 5
0
        public static ICreateTableWithColumnOrSchemaSyntax Text(this ICreateTableWithColumnOrSchemaSyntax self, string name, bool isNullable)
        {
            if (isNullable)
            {
                self.WithColumn(name).AsCustom(PostgresSpecificType.Text).Nullable();
            }
            else
            {
                self.WithColumn(name).AsCustom(PostgresSpecificType.Text).NotNullable();
            }

            return(self);
        }
Exemplo n.º 6
0
        public static ICreateTableWithColumnOrSchemaSyntax TimestampzAndDefault(this ICreateTableWithColumnOrSchemaSyntax self, string name, bool isNullable)
        {
            if (isNullable)
            {
                self.WithColumn(name).AsCustom(PostgresSpecificType.Timestampz).Nullable();
            }
            else
            {
                self.WithColumn(name).AsCustom(PostgresSpecificType.Timestampz).NotNullable().WithDefaultValue(PostgresFunction.NowTimestampzUTC);
            }

            return(self);
        }
Exemplo n.º 7
0
        public static ICreateTableWithColumnOrSchemaSyntax IntForeignKey(this ICreateTableWithColumnOrSchemaSyntax self,
                                                                         string name, string foreignTable, bool isNullable, bool isUnique = false, bool isPK = false, bool onDeleteCascade = false)
        {
            ICreateTableColumnOptionOrWithColumnSyntax col;

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

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

                if (!isPK)
                {
                    col.Indexed();
                }
            }

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

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

            return(self);
        }
Exemplo n.º 8
0
 internal static ICreateTableColumnOptionOrWithColumnSyntax AutoIdBig(this ICreateTableWithColumnOrSchemaSyntax self) =>
 self.WithColumn("id").AsCustom(PostgresSpecificType.IdentityBig).NotNullable().PrimaryKey();
Exemplo n.º 9
0
 public static ICreateTableColumnOptionOrWithColumnSyntax IsTest(this ICreateTableWithColumnOrSchemaSyntax self, bool defaultValue = false) =>
 self.WithColumn("is_test").AsBoolean().NotNullable().WithDefaultValue(defaultValue);
Exemplo n.º 10
0
 public static ICreateTableColumnOptionOrWithColumnSyntax IsActive(this ICreateTableWithColumnOrSchemaSyntax self, bool defaultValue = true) =>
 self.WithColumn("is_active").AsBoolean().NotNullable().WithDefaultValue(defaultValue);
Exemplo n.º 11
0
 public static ICreateTableColumnOptionOrWithColumnSyntax IdBig(this ICreateTableWithColumnOrSchemaSyntax self) =>
 self.WithColumn("id").AsInt64().NotNullable().PrimaryKey();
Exemplo n.º 12
0
 public static ICreateTableWithColumnOrSchemaSyntax IntId(this ICreateTableWithColumnOrSchemaSyntax self)
 {
     self.WithColumn("Id").AsInt32().NotNullable().PrimaryKey();
     return(self);
 }
 public static ICreateTableColumnOptionOrWithColumnSyntax WithColumn(this ICreateTableWithColumnOrSchemaSyntax tableBuilder, string name, DbType dbType, int size)
 {
     return(ColumnExtensions.GetTypedColumn(tableBuilder.WithColumn(name), dbType, size));
 }
Exemplo n.º 14
0
 public static ICreateTableColumnAsTypeSyntax WithColumn <TObject>(this ICreateTableWithColumnOrSchemaSyntax root,
                                                                   Expression <Func <TObject, object> > expression)
 {
     return(root.WithColumn(expression.ToMember().Name));
 }