mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Update Demo
This commit is contained in:
parent
4efd60a536
commit
f37973ebc6
@ -66,7 +66,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OceanBaseForOracleTest", "O
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlSugar.TDengineCore", "SqlSugar.TDengineCore\SqlSugar.TDengineCore.csproj", "{A8FDDB0E-835A-4042-A955-66A2DB98207D}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlSugar.TDengineCore", "SqlSugar.TDengineCore\SqlSugar.TDengineCore.csproj", "{A8FDDB0E-835A-4042-A955-66A2DB98207D}"
|
||||||
EndProject
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
@ -147,6 +148,18 @@ namespace OrmTest
|
|||||||
}).ToPageList(1,2);
|
}).ToPageList(1,2);
|
||||||
}
|
}
|
||||||
private static void UnitTest(SqlSugarClient db)
|
private static void UnitTest(SqlSugarClient db)
|
||||||
|
{
|
||||||
|
//类型测试
|
||||||
|
DbType(db);
|
||||||
|
|
||||||
|
//纳秒
|
||||||
|
NS();
|
||||||
|
|
||||||
|
//微秒
|
||||||
|
US();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DbType(SqlSugarClient db)
|
||||||
{
|
{
|
||||||
//更多类型查询测试
|
//更多类型查询测试
|
||||||
db.Ado.ExecuteCommand(@"
|
db.Ado.ExecuteCommand(@"
|
||||||
@ -159,24 +172,111 @@ namespace OrmTest
|
|||||||
`gateway_mac` VARCHAR(8),
|
`gateway_mac` VARCHAR(8),
|
||||||
`ruminate` SMALLINT,
|
`ruminate` SMALLINT,
|
||||||
`rssi` TINYINT) TAGS (`tag_id` VARCHAR(12))");
|
`rssi` TINYINT) TAGS (`tag_id` VARCHAR(12))");
|
||||||
var list=db.Queryable<fc_data>().ToList();
|
var list = db.Queryable<fc_data>().ToList();
|
||||||
//创建子表
|
//创建子表
|
||||||
db.Ado.ExecuteCommand(@"create table IF NOT EXISTS fc_data01 using `fc_data` tags('1')");
|
db.Ado.ExecuteCommand(@"create table IF NOT EXISTS fc_data01 using `fc_data` tags('1')");
|
||||||
db.Insertable(new fc_data() {
|
db.Insertable(new fc_data()
|
||||||
data_id= 1,
|
{
|
||||||
gateway_mac="mac",
|
data_id = 1,
|
||||||
rssi=11,
|
gateway_mac = "mac",
|
||||||
ruminate=1,
|
rssi = 11,
|
||||||
speed_hex="x",
|
ruminate = 1,
|
||||||
temperature=1,
|
speed_hex = "x",
|
||||||
upload_time=DateTime.Now,
|
temperature = 1,
|
||||||
voltage=1
|
upload_time = DateTime.Now,
|
||||||
|
voltage = 1
|
||||||
|
|
||||||
}).AS("fc_data01").ExecuteCommand();
|
}).AS("fc_data01").ExecuteCommand();
|
||||||
|
|
||||||
var list2 = db.Queryable<fc_data>().AS("fc_data01").ToList();
|
var list2 = db.Queryable<fc_data>().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<MyTable02_NS>().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<MyTable02_US>().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
private static List<MyTable02> GetInsertDatas()
|
private static List<MyTable02> GetInsertDatas()
|
||||||
{
|
{
|
||||||
return new List<MyTable02>() {
|
return new List<MyTable02>() {
|
||||||
|
46
Src/Asp.NetCore2/TDengineTest/Models/Unit/MyTable02_NS.cs
Normal file
46
Src/Asp.NetCore2/TDengineTest/Models/Unit/MyTable02_NS.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 纳秒
|
||||||
|
/// </summary>
|
||||||
|
[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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 微秒
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
[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; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user