SqlSugar/Src/Asp.Net/OracleTest/Demos/5_CodeFirst.cs

61 lines
1.8 KiB
C#
Raw Normal View History

2017-08-03 23:12:44 +08:00
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.Demo
{
public class CodeTable
{
2018-11-29 11:40:34 +08:00
[SugarColumn(IsPrimaryKey = true)]
2017-08-03 23:12:44 +08:00
public int Id { get; set; }
2018-11-29 11:40:34 +08:00
[SugarColumn(Length = 21, OldColumnName = "Name2", ColumnDescription = "haha")]
public string Name { get; set; }
[SugarColumn(IsNullable = true, Length = 10)]
2017-08-03 23:12:44 +08:00
public string IsOk { get; set; }
public Guid Guid { get; set; }
2018-11-29 11:40:34 +08:00
[SugarColumn(ColumnDataType = "int")]
2017-08-03 23:12:44 +08:00
public decimal Decimal { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime? DateTime { get; set; }
2018-11-29 11:40:34 +08:00
[SugarColumn(IsNullable = true, OldColumnName = "Dob")]
2017-08-03 23:12:44 +08:00
public double? Dob2 { get; set; }
2018-11-29 11:40:34 +08:00
[SugarColumn(Length = 110)]
public string A2 { get; set; }
2017-08-03 23:12:44 +08:00
}
2018-11-29 11:40:34 +08:00
public class CodeTable2
{
2017-08-03 23:12:44 +08:00
public int Id { get; set; }
public string Name { get; set; }
2018-11-29 11:40:34 +08:00
[SugarColumn(IsIgnore = true)]
2017-08-03 23:12:44 +08:00
public string TestId { get; set; }
}
2018-11-29 11:40:34 +08:00
public class GuidTable
{
public Guid Name { get; set; }
[SugarColumn(IsPrimaryKey = true)]
public Guid Id { get; set; }
}
2017-08-03 23:12:44 +08:00
public class CodeFirst : DemoBase
{
public static void Init()
{
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
2018-11-25 20:04:59 +08:00
DbType = DbType.Oracle,
2017-08-03 23:12:44 +08:00
IsAutoCloseConnection = true,
2018-11-29 11:40:34 +08:00
InitKeyType = InitKeyType.Attribute
2017-08-03 23:12:44 +08:00
});
//Backup table
//db.CodeFirst.BackupTable().InitTables(typeof(CodeTable),typeof(CodeTable2));
//No backup table
2018-11-29 11:40:34 +08:00
db.CodeFirst.InitTables(typeof(GuidTable), typeof(CodeTable), typeof(CodeTable2));
2017-08-03 23:12:44 +08:00
}
2018-11-29 11:40:34 +08:00
2017-08-03 23:12:44 +08:00
}
2018-11-29 11:40:34 +08:00
}