Comments (10)
We will provide the C# and library for windows soon. Please wait for a few weeks.
from tdengine.
https://github.com/maikebing/Maikebing.EntityFrameworkCore.Taos
from tdengine.
string database = "db_" + DateTime.Now.ToString("yyyyMMddHHmmss");
var builder = new TaosConnectionStringBuilder()
{
DataSource = "http://td.gitclub.cn/rest/sql",
DataBase = database,
// Token = "cm9vdDp0YW9zZGF0YQ=="
Username="root",
Password= "taosdata"
};
using (var connection = new TaosConnection(builder.ConnectionString))
{
connection.Open();
Console.WriteLine("create {0} {1}", database, connection.CreateCommand($"create database {database};").ExecuteNonQuery());
Console.WriteLine("create table t {0} {1}", database, connection.CreateCommand($"create table {database}.t (ts timestamp, cdata int);").ExecuteNonQuery());
Console.WriteLine("insert into t values {0} ", connection.CreateCommand($"insert into {database}.t values ('{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ms")}', 10);").ExecuteNonQuery());
Console.WriteLine("insert into t values {0} ", connection.CreateCommand($"insert into {database}.t values ('{DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss.ms")}', 20);").ExecuteNonQuery());
var cmd_select = connection.CreateCommand();
cmd_select.CommandText = $"select * from {database}.t";
var reader = cmd_select.ExecuteReader();
List<Dictionary<string, object>> valuePairs = new List<Dictionary<string, object>>();
while (reader.Read())
{
Dictionary<string, object> pairs = new Dictionary<string, object>();
for (int i = 0; i < reader.FieldCount; i++)
{
pairs.Add(reader.GetName(i), reader.GetValue(i));
}
valuePairs.Add(pairs);
}
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(valuePairs));
Console.WriteLine("DROP TABLE {0} {1}", database, connection.CreateCommand($"DROP TABLE {database}.t;").ExecuteNonQuery());
Console.WriteLine("DROP DATABASE {0} {1}", database, connection.CreateCommand($"DROP DATABASE {database}").ExecuteNonQuery());
Console.ReadKey();
connection.Close();
}
from tdengine.
Well, i have the same questions, is it possible to call TDEngine via C++ lib from C# application ?@windjmj
from tdengine.
Restfull api is an alternative choice
from tdengine.
yep,restful api indeed can meet your requirment, but cannt subscribe ,right?
from tdengine.
If the TDengine can support C# for dotnet core platform, it will be better, after all, dotnet core is the future.
from tdengine.
OK, restful api to ef.core is the first step, we still need more reliable and more efficient connection api from official.
from tdengine.
///Specify the name of the database
string database = "db_" + DateTime.Now.ToString("yyyyMMddHHmmss");
var builder = new TaosConnectionStringBuilder()
{
DataSource = "http://td.gitclub.cn/rest/sql",
DataBase = database,
Username = "root",
Password = "taosdata"
};
//Example for ADO.Net
using (var connection = new TaosConnection(builder.ConnectionString))
{
connection.Open();
Console.WriteLine("create {0} {1}", database, connection.CreateCommand($"create database {database};").ExecuteNonQuery());
Console.WriteLine("create table t {0} {1}", database, connection.CreateCommand($"create table {database}.t (ts timestamp, cdata int);").ExecuteNonQuery());
Console.WriteLine("insert into t values {0} ", connection.CreateCommand($"insert into {database}.t values ('{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ms")}', 10);").ExecuteNonQuery());
Console.WriteLine("insert into t values {0} ", connection.CreateCommand($"insert into {database}.t values ('{DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss.ms")}', 20);").ExecuteNonQuery());
Console.WriteLine("==================================================================");
var cmd_select = connection.CreateCommand();
cmd_select.CommandText = $"select * from {database}.t";
var reader = cmd_select.ExecuteReader();
ConsoleTableBuilder.From(reader.ToDataTable()).WithFormat(ConsoleTableBuilderFormat.MarkDown).ExportAndWriteLine();
Console.WriteLine("==================================================================");
Console.WriteLine("DROP TABLE {0} {1}", database, connection.CreateCommand($"DROP TABLE {database}.t;").ExecuteNonQuery());
Console.WriteLine("DROP DATABASE {0} {1}", database, connection.CreateCommand($"DROP DATABASE {database}").ExecuteNonQuery());
connection.Close();
}
//Example for Entity Framework Core
using (var context = new TaosContext(new DbContextOptionsBuilder()
.UseTaos(builder.ConnectionString).Options))
{
Console.WriteLine("EnsureCreated");
context.Database.EnsureCreated();
for (int i = 0; i < 10; i++)
{
var rd = new Random();
context.sensor.Add(new sensor() { ts = DateTime.Now.AddMilliseconds(i), degree = rd.NextDouble(), pm25 = rd.Next(0, 1000) });
}
Console.WriteLine("SaveChanges.....");
context.SaveChanges();
Console.WriteLine("==================================================================");
Console.WriteLine("Search pm25>0");
var f = from s in context.sensor where s.pm25 > 0 select s;
var ary = f.ToArray();
ConsoleTableBuilder.From(ary.ToList()).WithFormat(ConsoleTableBuilderFormat.MarkDown).ExportAndWriteLine();
Console.WriteLine("==================================================================");
context.Database.EnsureDeleted();
}
}
from tdengine.
from tdengine.
Related Issues (20)
- dbeaver 连接报错 HOT 1
- rpc open too many session HOT 1
- 在 Kubernetes 上部署 TDengine 集群,显示错误dnode file:/var/lib/taos//dnode/dnode.json not exist,无法建立连接 HOT 3
- tdengine 同样的一条数据查询速度变慢
- Password too long leads to authentication failed HOT 1
- datadir目录修改问题 HOT 1
- TDengine's queries slow down after inserting the same data all the time HOT 1
- 关于TDengine集群高可用使用过程中产生的疑惑 HOT 1
- 想问windows服务端还继续维护吗?已经很久没有发布了 HOT 1
- Golang restful batch insert bug
- taosInitLog memory overflow when using taos_schemalsss_insert
- It is not clear how many times each consumer poll operation needs to be performed HOT 3
- taosd crash led by query HOT 1
- Sync leader is restoring HOT 1
- 是否可以在调用taos_cleanup后再调用taos_init? HOT 5
- TDengineException: Version not compatible HOT 2
- 调用taos_cleanup后无法再调用tao_init正确初始化taos环境 HOT 1
- show database abnormal
- Clent and server's time is not synchronized
- regrading to the start window of interval
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tdengine.