-
Notifications
You must be signed in to change notification settings - Fork 1.4k
E.CodeFirst
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 |
db.CodeFirst.InitTables(typeof(CodeFirstTable));
[SugarTable("CodeFirstTable2",TableDescription = "TableDescription")]
public class CodeFirstTable
{
[SugarColumn(IsPrimaryKey = true)]
public Guid Id { get; set; }
}