SqlSugar/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs

68 lines
2.0 KiB
C#
Raw Normal View History

2021-05-15 22:17:39 +08:00
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public partial class NewUnitTest
{
public static void CodeFirst()
{
2021-01-01 18:16:05 +08:00
Db.CodeFirst.InitTables<UnitCodeFirstpks2>();
if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false))
Db.DbMaintenance.DropTable("UnitCodeTest1");
Db.CodeFirst.InitTables<UnitCodeTest1>();
2021-01-01 18:16:05 +08:00
Db.CodeFirst.InitTables<UnitCodeFirstpks2>();
2021-02-11 18:50:33 +08:00
var db = Db;
db.Aop.OnLogExecuting = (s, p) =>
{
Console.WriteLine(s);
};
Db.CodeFirst.InitTables<UnitCodeFirstpks3>();
2021-03-11 21:48:45 +08:00
Db.CodeFirst.InitTables<UnitCodeFirstpks32>();
2021-05-15 22:17:39 +08:00
db.CodeFirst.InitTables<UnitTest0122132>();
2021-03-11 21:48:45 +08:00
}
2021-05-15 22:17:39 +08:00
public class UnitTest0122132
{
2021-03-11 21:48:45 +08:00
2021-05-15 22:17:39 +08:00
[SugarColumn(ColumnDataType = "image,longblob")]
public byte[] x { get; set; }
}
2021-03-11 21:48:45 +08:00
[SqlSugar.SugarTable("[dbo].[UnitCodeFirstpks3aaa122]")]
public class UnitCodeFirstpks32
{
public int id { get; set; }
public string name2 { get; set; }
2021-02-11 18:50:33 +08:00
}
2021-02-11 19:10:42 +08:00
[SqlSugar.SugarTable("UnitCodeFirstpks31","备注" )]
2021-02-11 18:50:33 +08:00
public class UnitCodeFirstpks3
{
public int id { get; set; }
2021-02-11 19:10:42 +08:00
public string name2 { get; set; }
2021-02-11 18:50:33 +08:00
2021-01-01 18:16:05 +08:00
}
public class UnitCodeFirstpks2
{
[SqlSugar.SugarColumn(IsPrimaryKey =true)]
public string id { get; set; }
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
public string id2 { get; set; }
}
public class UnitCodeTest1
{
[SqlSugar.SugarColumn(IndexGroupNameList = new string[] { "group1" })]
public int Id { get; set; }
[SqlSugar.SugarColumn(DefaultValue="getdate()", IndexGroupNameList =new string[] {"group1" } )]
public DateTime? CreateDate { get; set; }
}
}
}