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

Generating database tables based on entities

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

SugarColumn attribute Description

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

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

Clone this wiki locally