diff --git a/Src/Asp.NetCore2/SqlSugarCore.sln b/Src/Asp.NetCore2/SqlSugarCore.sln index 43010d4be..078e613a5 100644 --- a/Src/Asp.NetCore2/SqlSugarCore.sln +++ b/Src/Asp.NetCore2/SqlSugarCore.sln @@ -66,7 +66,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OceanBaseForOracleTest", "O EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlSugar.TDengineCore", "SqlSugar.TDengineCore\SqlSugar.TDengineCore.csproj", "{A8FDDB0E-835A-4042-A955-66A2DB98207D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "1TDengineTest", "TDengineTest\1TDengineTest.csproj", "{AFBF6813-DA87-4621-9659-5D123234CDDF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "1TDengineTest", "TDengineTest\1TDengineTest.csproj", "{AFBF6813-DA87-4621-9659-5D123234CDDF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Src/Asp.NetCore2/TDengineTest/Demo/ORMTest.cs b/Src/Asp.NetCore2/TDengineTest/Demo/ORMTest.cs index a71bb577b..0114104b1 100644 --- a/Src/Asp.NetCore2/TDengineTest/Demo/ORMTest.cs +++ b/Src/Asp.NetCore2/TDengineTest/Demo/ORMTest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using SqlSugar; @@ -147,6 +148,18 @@ namespace OrmTest }).ToPageList(1,2); } private static void UnitTest(SqlSugarClient db) + { + //类型测试 + DbType(db); + + //纳秒 + NS(); + + //微秒 + US(); + } + + private static void DbType(SqlSugarClient db) { //更多类型查询测试 db.Ado.ExecuteCommand(@" @@ -159,24 +172,111 @@ namespace OrmTest `gateway_mac` VARCHAR(8), `ruminate` SMALLINT, `rssi` TINYINT) TAGS (`tag_id` VARCHAR(12))"); - var list=db.Queryable().ToList(); + var list = db.Queryable().ToList(); //创建子表 db.Ado.ExecuteCommand(@"create table IF NOT EXISTS fc_data01 using `fc_data` tags('1')"); - db.Insertable(new fc_data() { - data_id= 1, - gateway_mac="mac", - rssi=11, - ruminate=1, - speed_hex="x", - temperature=1, - upload_time=DateTime.Now, - voltage=1 + db.Insertable(new fc_data() + { + data_id = 1, + gateway_mac = "mac", + rssi = 11, + ruminate = 1, + speed_hex = "x", + temperature = 1, + upload_time = DateTime.Now, + voltage = 1 }).AS("fc_data01").ExecuteCommand(); var list2 = db.Queryable().AS("fc_data01").ToList(); } + private static void NS() + { + //说明: + //字符串中指定TsType=config_ns + //实体加上 SqlParameterDbType =typeof(DateTime19) + + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { + DbType=SqlSugar.DbType.TDengine, + IsAutoCloseConnection=true, + ConnectionString = "Host=localhost;Port=6030;Username=root;Password=taosdata;Database=nstest;TsType=config_ns" }); + + //删除库-库上限比太少只能删了测试 + if(db.DbMaintenance.GetDataBaseList().Any(it=>it== "nstest")) + { + db.Ado.ExecuteCommand("drop database nstest"); + } + + db.DbMaintenance.CreateDatabase();//创建纳秒库 + + //建超级表 + db.Ado.ExecuteCommand("CREATE STABLE IF NOT EXISTS St01 (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT, isdelete BOOL, name BINARY(64)) TAGS (location BINARY(64), groupId INT)"); + + //创建子表 + db.Ado.ExecuteCommand(@"create table IF NOT EXISTS MyTable02 using St01 tags('California.SanFrancisco',1)"); + + + //查询子表 + var dt = db.Ado.GetDataTable("select * from MyTable02 "); + + + //插入单条子表 + db.Insertable(new MyTable02_NS() + { + ts = DateTime.Now, + current = Convert.ToSingle(1.1), + groupId = 1, + isdelete = true, + name = "haha", + location = "aa", + phase = Convert.ToSingle(1.2), + voltage = 11 + }).ExecuteCommand(); + var list=db.Queryable().ToList(); + } + private static void US() + { + //说明: + //字符串中指定TsType=config_ns + //实体加上 SqlParameterDbType =typeof(DateTime19) + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() + { + DbType = SqlSugar.DbType.TDengine, + IsAutoCloseConnection = true, + ConnectionString = "Host=localhost;Port=6030;Username=root;Password=taosdata;Database=nstest;TsType=config_us" + }); + //删除库-库上限比太少只能删了测试 + db.Ado.ExecuteCommand("drop database nstest"); + + db.DbMaintenance.CreateDatabase();//创建纳秒库 + + //建超级表 + db.Ado.ExecuteCommand("CREATE STABLE IF NOT EXISTS St01 (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT, isdelete BOOL, name BINARY(64)) TAGS (location BINARY(64), groupId INT)"); + + //创建子表 + db.Ado.ExecuteCommand(@"create table IF NOT EXISTS MyTable02 using St01 tags('California.SanFrancisco',1)"); + + + //查询子表 + var dt = db.Ado.GetDataTable("select * from MyTable02 "); + + + //插入单条子表 + db.Insertable(new MyTable02_US() + { + ts = DateTime.Now, + current = Convert.ToSingle(1.1), + groupId = 1, + isdelete = true, + name = "haha", + location = "aa", + phase = Convert.ToSingle(1.2), + voltage = 11 + }).ExecuteCommand(); + var list = db.Queryable().ToList(); + } + private static List GetInsertDatas() { return new List() { diff --git a/Src/Asp.NetCore2/TDengineTest/Models/Unit/MyTable02_NS.cs b/Src/Asp.NetCore2/TDengineTest/Models/Unit/MyTable02_NS.cs new file mode 100644 index 000000000..46bffe911 --- /dev/null +++ b/Src/Asp.NetCore2/TDengineTest/Models/Unit/MyTable02_NS.cs @@ -0,0 +1,46 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Text; + +namespace OrmTest +{ + /// + /// 纳秒 + /// + [SugarTable("MyTable02")] + public class MyTable02_NS + { + [SugarColumn(IsPrimaryKey = true,SqlParameterDbType =typeof(DateTime19))] + public DateTime ts { get; set; } + public float current { get; set; } + public bool isdelete { get; set; } + public string name { get; set; } + public int voltage { get; set; } + public float phase { get; set; } + [SugarColumn(IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true)] + public string location { get; set; } + [SugarColumn(IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true)] + public int groupId { get; set; } + } + + /// + /// 微秒 + /// + + [SugarTable("MyTable02")] + public class MyTable02_US + { + [SugarColumn(IsPrimaryKey = true, SqlParameterDbType = typeof(DateTime16))] + public DateTime ts { get; set; } + public float current { get; set; } + public bool isdelete { get; set; } + public string name { get; set; } + public int voltage { get; set; } + public float phase { get; set; } + [SugarColumn(IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true)] + public string location { get; set; } + [SugarColumn(IsOnlyIgnoreInsert = true, IsOnlyIgnoreUpdate = true)] + public int groupId { get; set; } + } +}