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

93 lines
3.2 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()
{
if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false))
Db.DbMaintenance.DropTable("UnitCodeTest1");
Db.CodeFirst.InitTables<UnitCodeTest1>();
2020-12-20 02:02:39 +08:00
Db.CodeFirst.InitTables<UnitCodeTest2222>();
Db.Insertable(new UnitCodeTest2222()
{
Id = 1,
Id2 = 2,
Id3 = 3,
2021-01-29 21:17:38 +08:00
Id4 = 4
2020-12-20 02:02:39 +08:00
}).ExecuteCommand();
var list = Db.Queryable<UnitCodeTest2222>().ToList();
2021-01-29 21:17:38 +08:00
Db.CodeFirst.InitTables<UnitCodeTest2a2c22>();
Db.Insertable(new UnitCodeTest2a2c22()
{
a = 1,
b = new byte[] { 1, 2, 3 }
})
.ExecuteCommand();
var xx=Db.Queryable<UnitCodeTest2a2c22>().Select(it => new
{
id=it.a,
b=it.b
}).ToList();
2021-05-15 22:17:39 +08:00
Db.CodeFirst.InitTables<UnitTest012213>();
2021-11-01 22:12:49 +08:00
Db.CodeFirst.InitTables<UnitTest3131>();
2021-12-07 18:44:17 +08:00
Db.CodeFirst.InitTables<UnitDateOfTime2>();
2021-12-11 15:17:31 +08:00
Db.CodeFirst.InitTables<UnitDateOfTime222>();
2021-12-07 18:44:17 +08:00
Db.Insertable(new UnitDateOfTime2() { DateTimeOffset1 = DateTimeOffset.Now }).ExecuteCommand();
2021-12-07 19:49:02 +08:00
Db.Insertable(new List<UnitDateOfTime2> { new UnitDateOfTime2() { DateTimeOffset1 = DateTimeOffset.Now }, new UnitDateOfTime2() { DateTimeOffset1 = DateTimeOffset.Now } }).ExecuteCommand();
2021-12-07 18:44:17 +08:00
var list2 = Db.Queryable<UnitDateOfTime2>().ToList();
2021-12-11 15:17:31 +08:00
Db.Insertable(new UnitDateOfTime222() { DateTimeOffset1 = null }).ExecuteCommand();
2021-12-07 18:44:17 +08:00
}
public class UnitDateOfTime2
{
[SqlSugar.SugarColumn(ColumnDataType ="datetime(3)")]
public DateTimeOffset DateTimeOffset1 { get; set; }
2021-11-01 22:12:49 +08:00
}
2021-12-11 15:17:31 +08:00
public class UnitDateOfTime222
{
[SqlSugar.SugarColumn(ColumnDataType = "datetime(3)",IsNullable =true)]
public DateTimeOffset? DateTimeOffset1 { get; set; }
}
2021-11-01 22:12:49 +08:00
public class UnitTest3131
{
public sbyte Id { get; set; }
2021-05-15 22:17:39 +08:00
}
public class UnitTest012213
{
[SugarColumn(ColumnDataType = "image,longblob")]
public byte[] x { get; set; }
}
public class UnitCodeTest1
{
[SqlSugar.SugarColumn(IndexGroupNameList = new string[] { "group1" })]
public int Id { get; set; }
2019-06-04 16:25:54 +08:00
[SqlSugar.SugarColumn(DefaultValue="now()", IndexGroupNameList =new string[] {"group1" } )]
public DateTime? CreateDate { get; set; }
}
2021-01-29 21:17:38 +08:00
public class UnitCodeTest2a2c22
{
public int a { get; set; }
[SqlSugar.SugarColumn(ColumnDataType ="blob")]
public byte[] b { get; set; }
}
2020-12-20 02:02:39 +08:00
public class UnitCodeTest2222
{
public uint Id { get; set; }
public ulong Id2 { get; set; }
public ushort Id3 { get; set; }
public uint? Id4 { get; set; }
}
}
}