예제 #1
0
        public static string CreateTableCode(EntityConfig entity, bool signle = false)
        {
            if (entity.IsClass)
            {
                return(null);
            }
            var code = new StringBuilder();

            if (entity.PrimaryColumn != null)
            {
                code.AppendFormat(@"
/*{1}*/
CREATE TABLE `{0}`("
                                  , entity.SaveTable
                                  , entity.Caption);

                code.Append($@"
    `{entity.PrimaryColumn.ColumnName}` {DataBaseHelper.ColumnType(entity.PrimaryColumn)} NOT NULL{
                        (entity.PrimaryColumn.IsIdentity ? " AUTO_INCREMENT" : null)
                    } COMMENT '{entity.PrimaryColumn.Caption}'");
            }
            foreach (PropertyConfig col in entity.DbFields.Where(p => !p.IsCompute))
            {
                if (col.IsPrimaryKey)
                {
                    continue;
                }
                code.Append($@"
   ,{FieldDefault(col)}");
            }
            if (entity.PrimaryColumn != null)
            {
                code.Append($@"
    ,PRIMARY KEY (`{entity.PrimaryColumn.ColumnName}`)");
            }
            //if (entity.PrimaryColumn.IsIdentity)

            code.Append($@"
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '{entity.Caption}'");
            //if (entity.PrimaryColumn.IsIdentity)
            //    code.Append(@" AUTO_INCREMENT=1");
            code.Append(@";");
            return(code.ToString());
        }
예제 #2
0
 private static string FieldDefault(PropertyConfig col)
 {
     return($"`{col.ColumnName}` {DataBaseHelper.ColumnType(col)}{NullKeyWord(col)} {ColumnDefault(col)} COMMENT '{col.Caption}'");
 }