SqlSugar/Src/Asp.NetCore2/TDengineTest/Demo/ORMTest.cs

62 lines
1.6 KiB
C#
Raw Normal View History

2023-07-31 18:55:12 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
2023-09-07 16:47:44 +08:00
using System.Runtime.CompilerServices;
2023-07-31 18:55:12 +08:00
using System.Text;
using System.Threading.Tasks;
2023-12-23 17:39:41 +08:00
using SqlSugar;
using SqlSugar.DbConvert;
2023-07-31 23:59:42 +08:00
2023-10-01 15:25:49 +08:00
namespace TDengineTest
2023-07-31 18:55:12 +08:00
{
2023-10-01 15:25:49 +08:00
public partial class ORMTest
2023-07-31 18:55:12 +08:00
{
public static void Init()
{
2023-07-31 23:59:42 +08:00
var db = new SqlSugarClient(new ConnectionConfig()
2023-07-31 18:55:12 +08:00
{
2023-07-31 23:59:42 +08:00
DbType = SqlSugar.DbType.TDengine,
2023-07-31 18:55:12 +08:00
ConnectionString = Config.ConnectionString,
IsAutoCloseConnection = true,
AopEvents = new AopEvents
{
OnLogExecuting = (sql, p) =>
{
2023-08-16 17:42:34 +08:00
Console.WriteLine(UtilMethods.GetNativeSql(sql, p));
2023-07-31 18:55:12 +08:00
}
2023-12-23 17:39:41 +08:00
},
ConfigureExternalServices = new ConfigureExternalServices()
{
EntityService= (property, column) =>
{
if (column.SqlParameterDbType == null)
{
column.SqlParameterDbType = typeof(CommonPropertyConvert);
}
}
2023-07-31 18:55:12 +08:00
}
});
2023-10-01 20:16:14 +08:00
2023-10-01 15:31:34 +08:00
//建表
CodeFirst(db);
//生成实体
DbFirst(db);
2023-08-16 17:42:34 +08:00
//简单用例
2023-10-01 15:31:34 +08:00
Demo1(db);
2023-08-08 19:03:31 +08:00
2023-10-01 15:31:34 +08:00
//测试用例 (纳秒、微妙、类型)
2023-08-16 17:42:34 +08:00
UnitTest(db);
2023-08-08 19:26:23 +08:00
2023-10-01 15:25:49 +08:00
Console.WriteLine("执行完成");
Console.ReadKey();
2023-08-08 19:03:31 +08:00
}
2023-07-31 18:55:12 +08:00
}
}