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

176 lines
6.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-09-04 18:30:15 +08:00
Db.CodeFirst.InitTables<UnitTimeSpan2>();
Db.Insertable(new UnitTimeSpan2()
{
Id = new TimeSpan(),
id2 = new TimeSpan(11, 2, 1)
}).ExecuteCommand();
var x = Db.Queryable<UnitTimeSpan2>().ToList();
2021-12-07 21:44:23 +08:00
Db.CodeFirst.InitTables<UnitDateOfTime2>();
Db.Insertable(new UnitDateOfTime2() { DateTimeOffset1 = DateTimeOffset.Now }).ExecuteCommand();
Db.Insertable(new List<UnitDateOfTime2> { new UnitDateOfTime2() { DateTimeOffset1 = DateTimeOffset.Now }, new UnitDateOfTime2() { DateTimeOffset1 = DateTimeOffset.Now } }).ExecuteCommand();
var list2 = Db.Queryable<UnitDateOfTime2>().ToList();
2022-01-25 12:05:41 +08:00
try
{
Db.Ado.ExecuteCommand(@" create schema abp");
}
catch
{
}
2022-04-23 20:50:19 +08:00
try
{
Db.Ado.ExecuteCommand(@" create schema [user]");
}
catch
{
}
2022-04-23 21:52:22 +08:00
try
{
Db.Ado.ExecuteCommand(@" create schema [ddd]");
}
catch
{
}
2022-01-25 12:05:41 +08:00
db.CodeFirst.InitTables<UnitTableName>();
2022-02-14 13:59:24 +08:00
db.CodeFirst.InitTables<UnitGe>();
db.Insertable(new UnitGe() { geometry1 = "POINT (20 180)" }).ExecuteCommand();
var gelist=db.Queryable<UnitGe>().Select(it=>new { geometry1 = it.geometry1.ToString()}).ToList();
2022-04-13 23:38:12 +08:00
if (Db.DbMaintenance.IsAnyTable("User", false))
Db.DbMaintenance.DropTable("User");
db.CodeFirst.InitTables<User>();
2022-04-23 15:45:08 +08:00
Db.CodeFirst.InitTables<UnitCodeFirstpks2>();
if (Db.DbMaintenance.IsAnyTable("UnitCodeFirst131", false))
Db.DbMaintenance.DropTable("UnitCodeFirst131");
Db.CodeFirst.InitTables<UnitCodeFirst131>();
Db.Insertable(new UnitCodeFirst131() { Id = 1 }).ExecuteCommand();
Db.CodeFirst.InitTables<UNITCODEFIRST131>();
Db.CodeFirst.InitTables<UNITCOdEFIRST131>();
2022-04-23 20:50:19 +08:00
Db.CodeFirst.InitTables<UnitTableUserName>();
2022-04-23 21:52:22 +08:00
db.CodeFirst.InitTables<UnitTablename>();
2022-04-23 15:45:08 +08:00
}
public class UnitCodeFirst131
{
public int Id { get; set; }
}
public class UNITCODEFIRST131
{
public int Id { get; set; }
[SqlSugar.SugarColumn(DefaultValue = "a")]
public string Name { get; set; }
}
public class UNITCOdEFIRST131
{
public int Id { get; set; }
[SqlSugar.SugarColumn(DefaultValue = "a")]
public string Name { get; set; }
[SqlSugar.SugarColumn(DefaultValue = "getdate()")]
public DateTime dt { get; set; }
2022-04-13 23:38:12 +08:00
}
public class User
{
[SugarColumn(IndexGroupNameList =new string[] { "index"})]
public int key { get; set; }
[SugarColumn(UniqueGroupNameList = new string[] { "index" })]
public int key2 { get; set; }
2022-02-14 13:59:24 +08:00
}
public class UnitGe
{
[SugarColumn(ColumnDataType = "geometry")]
public string geometry1 { get; set; }
2022-01-25 12:05:41 +08:00
}
2022-02-14 13:59:24 +08:00
2022-01-25 12:05:41 +08:00
[SugarTable("abp.UnitTableName","备注")]
public class UnitTableName
{
public string Id { get; set; }
2021-12-07 21:44:23 +08:00
}
2022-04-23 21:52:22 +08:00
[SugarTable("ddd.UnitTableName", "备注")]
public class UnitTablename
{
public string Id { get; set; }
}
2021-12-07 21:44:23 +08:00
public class UnitDateOfTime2
{
public DateTimeOffset DateTimeOffset1 { get; set; }
2021-09-04 18:30:15 +08:00
}
public class UnitTimeSpan2
{
[SqlSugar.SugarColumn(ColumnDataType = "time")]
public TimeSpan Id { get; set; }
public TimeSpan id2 { get; set; }
2021-03-11 21:48:45 +08:00
}
2022-04-23 20:50:19 +08:00
[SugarTable("user.UnitTableUserName", "备注")]
public class UnitTableUserName
{
public string Id { get; set; }
}
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; }
}
}
}