Skip to content
sunkaixuan edited this page May 7, 2019 · 20 revisions

Generating database tables based on entities

## SugarColumn attribute Description
public class CodeFirstTable1
{
        [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
        public int Id { get; set; }
        public string Name { get; set; }
        [SugarColumn(ColumnDataType = "Nvarchar(255)")]//custom
        public string Text { get; set; }
        [SugarColumn(IsNullable = true)]
        public DateTime CreateTime { get; set; }
}

db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create table
IsIdentity Create identity
IsPrimaryKey Create primaryKey
ColumnName Custom database column name
IsIgnore Ignore property
IsOnlyIgnoreInsert insert Ignore property
ColumnDescription Create column description
Length column length
IsNullable column is nullable
DecimalDigits decimal(18,2) length=18,DecimalDigits=2
OracleSequenceName equivalent to identity column

SugarTable attribute Description

db.CodeFirst.InitTables(typeof(CodeFirstTable));

[SugarTable("CodeFirstTable2",TableDescription = "TableDescription")]
public class CodeFirstTable
{
   [SugarColumn(IsPrimaryKey = true)]
   public Guid Id { get; set; }
}

Clone this wiki locally