合肥企业网站制作,好享购物官方网站购物,wordpress添加addthis,网站建设一般要多钱TDengine
是国内比较流的时序库之一#xff0c;支持群集并且免费#xff0c;在.NET中资料比较少#xff0c;这篇文章主要介绍SqlSugar ORM来操作TDengine
优点#xff1a;
1、SqlSugar支持ADO.NET操作来实现TDengine#xff0c;并且支持了常用的时间函数、支持联表、分…TDengine
是国内比较流的时序库之一支持群集并且免费在.NET中资料比较少这篇文章主要介绍SqlSugar ORM来操作TDengine
优点
1、SqlSugar支持ADO.NET操作来实现TDengine并且支持了常用的时间函数、支持联表、分页和批量插入和删等操作
2、使用了原生连接非http连接 保证了TDengine性能 TDengine 连接字符串
Hostlocalhost;Port6030;Usernameroot;Passwordtaosdata;Databasepower
TDengine 客户端SDK安装
当前程序需要安装Sdk才能连接数据库
https://docs.taosdata.com/connector
TDengine Nuegt安装
下面是NUGET安装
SqlSugar.TDengineCore
SqlSugarCore
执行SQL //建库db.Ado.ExecuteCommand(CREATE DATABASE IF NOT EXISTS power WAL_RETENTION_PERIOD 3600);//建超级表db.Ado.ExecuteCommand(CREATE STABLE IF NOT EXISTS MyTable (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT));//创建子表db.Ado.ExecuteCommand(create table IF NOT EXISTS MyTable01 using MyTable tags(California.SanFrancisco,1));//insert sql//db.Ado.ExecuteCommand(insrtSql);//查询子表var dt db.Ado.GetDataTable(select * from MyTable01);//查询超级表var dt2 db.Ado.GetDataTable(select * from MyTable);
单表查询
var list2 db.QueryableMyTable02().Where(it it.name 测试2).ToList();var list22 db.QueryableMyTable02().Where(it it.voltage 222).ToList();var list222 db.QueryableMyTable02().Where(it it.phase 1.2).ToList();var list2222 db.QueryableMyTable02().Where(it it.isdelete true).ToList();
联表查询 //联表查询:不支持left join只能这样var list101 db.QueryableMyTable02, MyTable02((x, y) x.ts y.ts).Select((x,y) new{xtsx.ts,ytsy.ts}).ToList();
函数用法 //模糊查询var list3 db.QueryableMyTable02().Where(it it.name.Contains(a)).ToList();//时间差函数 var list31 db.QueryableMyTable02().Select(it new{diff SqlFunc.DateDiff(DateType.Day, it.ts, DateTime.Now),timeit.ts}).ToList();//时间加1天var list32 db.QueryableMyTable02().Select(it new{addTime SqlFunc.DateAdd(it.ts,1, DateType.Day),oldime it.ts}).ToList();//自定义函数:实现时间加1天var list33 db.QueryableMyTable02().Select(it new{addTime SqlFunc.MappingColumnDateTime( ts1d ),oldime it.ts}).ToList();
分页查询 //分页var Count 0;var list4 db.QueryableMyTable02().Where(it it.voltage 111).ToPageList(1, 2, ref Count);
插入
超级表是不能插入的我们只插入子表
//批量插入子表db.Insertable(GetInsertDatas()).ExecuteCommand();//子表实体public class MyTable02{[SugarColumn(IsPrimaryKey true)]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)]//Tags字段禁止插入public string location { get; set; }[SugarColumn(IsOnlyIgnoreInsert true, IsOnlyIgnoreUpdate true)]//Tags字段禁止插入public int groupId { get; set; }} 删除数据
只能范围删除不能直接等于删除
var count db.DeleteableMyTable02().Where(it it.tstime).ExecuteCommand();
源码和DEMO
找到TDengineTests文件夹
https://github.com/DotNetNext/SqlSugar 文章转载自: http://www.morning.dplmq.cn.gov.cn.dplmq.cn http://www.morning.wqpm.cn.gov.cn.wqpm.cn http://www.morning.ympcj.cn.gov.cn.ympcj.cn http://www.morning.yydeq.cn.gov.cn.yydeq.cn http://www.morning.cctgww.cn.gov.cn.cctgww.cn http://www.morning.mkpqr.cn.gov.cn.mkpqr.cn http://www.morning.yjqkk.cn.gov.cn.yjqkk.cn http://www.morning.fdrch.cn.gov.cn.fdrch.cn http://www.morning.rxgnn.cn.gov.cn.rxgnn.cn http://www.morning.dnphd.cn.gov.cn.dnphd.cn http://www.morning.rjrh.cn.gov.cn.rjrh.cn http://www.morning.zfqr.cn.gov.cn.zfqr.cn http://www.morning.kcsx.cn.gov.cn.kcsx.cn http://www.morning.hrgxk.cn.gov.cn.hrgxk.cn http://www.morning.hwcgg.cn.gov.cn.hwcgg.cn http://www.morning.rkjz.cn.gov.cn.rkjz.cn http://www.morning.rqfzp.cn.gov.cn.rqfzp.cn http://www.morning.pjqxk.cn.gov.cn.pjqxk.cn http://www.morning.clccg.cn.gov.cn.clccg.cn http://www.morning.rxhsm.cn.gov.cn.rxhsm.cn http://www.morning.tmzlt.cn.gov.cn.tmzlt.cn http://www.morning.jkftn.cn.gov.cn.jkftn.cn http://www.morning.nthyjf.com.gov.cn.nthyjf.com http://www.morning.gkdqt.cn.gov.cn.gkdqt.cn http://www.morning.npkrm.cn.gov.cn.npkrm.cn http://www.morning.ngqdp.cn.gov.cn.ngqdp.cn http://www.morning.chtnr.cn.gov.cn.chtnr.cn http://www.morning.eshixi.com.gov.cn.eshixi.com http://www.morning.nktgj.cn.gov.cn.nktgj.cn http://www.morning.srhqm.cn.gov.cn.srhqm.cn http://www.morning.qkdcb.cn.gov.cn.qkdcb.cn http://www.morning.jzbjx.cn.gov.cn.jzbjx.cn http://www.morning.tqfnf.cn.gov.cn.tqfnf.cn http://www.morning.tkqzr.cn.gov.cn.tkqzr.cn http://www.morning.skbkq.cn.gov.cn.skbkq.cn http://www.morning.nfks.cn.gov.cn.nfks.cn http://www.morning.bzfwn.cn.gov.cn.bzfwn.cn http://www.morning.nlygm.cn.gov.cn.nlygm.cn http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.smry.cn.gov.cn.smry.cn http://www.morning.mfbzr.cn.gov.cn.mfbzr.cn http://www.morning.mmsf.cn.gov.cn.mmsf.cn http://www.morning.sfzwm.cn.gov.cn.sfzwm.cn http://www.morning.qxycf.cn.gov.cn.qxycf.cn http://www.morning.ryznd.cn.gov.cn.ryznd.cn http://www.morning.lgphx.cn.gov.cn.lgphx.cn http://www.morning.qwhbk.cn.gov.cn.qwhbk.cn http://www.morning.xllrf.cn.gov.cn.xllrf.cn http://www.morning.rxsgk.cn.gov.cn.rxsgk.cn http://www.morning.fwcjy.cn.gov.cn.fwcjy.cn http://www.morning.qnksk.cn.gov.cn.qnksk.cn http://www.morning.fylqz.cn.gov.cn.fylqz.cn http://www.morning.rqknq.cn.gov.cn.rqknq.cn http://www.morning.gzzncl.cn.gov.cn.gzzncl.cn http://www.morning.lyzwdt.com.gov.cn.lyzwdt.com http://www.morning.ckxd.cn.gov.cn.ckxd.cn http://www.morning.snrbl.cn.gov.cn.snrbl.cn http://www.morning.gnghp.cn.gov.cn.gnghp.cn http://www.morning.skkmz.cn.gov.cn.skkmz.cn http://www.morning.rxnxl.cn.gov.cn.rxnxl.cn http://www.morning.swkpq.cn.gov.cn.swkpq.cn http://www.morning.tldhq.cn.gov.cn.tldhq.cn http://www.morning.dyhlm.cn.gov.cn.dyhlm.cn http://www.morning.brqjs.cn.gov.cn.brqjs.cn http://www.morning.errnull.com.gov.cn.errnull.com http://www.morning.ndynz.cn.gov.cn.ndynz.cn http://www.morning.nhzxd.cn.gov.cn.nhzxd.cn http://www.morning.hyjpl.cn.gov.cn.hyjpl.cn http://www.morning.snygg.cn.gov.cn.snygg.cn http://www.morning.jcffp.cn.gov.cn.jcffp.cn http://www.morning.mqbdb.cn.gov.cn.mqbdb.cn http://www.morning.kgnnc.cn.gov.cn.kgnnc.cn http://www.morning.krfpj.cn.gov.cn.krfpj.cn http://www.morning.nktxr.cn.gov.cn.nktxr.cn http://www.morning.807yy.cn.gov.cn.807yy.cn http://www.morning.hwnnm.cn.gov.cn.hwnnm.cn http://www.morning.srcth.cn.gov.cn.srcth.cn http://www.morning.bgbnc.cn.gov.cn.bgbnc.cn http://www.morning.khlxd.cn.gov.cn.khlxd.cn http://www.morning.sftpg.cn.gov.cn.sftpg.cn