diff --git a/Src/Asp.Net/QuestDbTest/App.config b/Src/Asp.Net/QuestDbTest/App.config
new file mode 100644
index 000000000..4cbb741d0
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/App.config
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Src/Asp.Net/QuestDbTest/Config.cs b/Src/Asp.Net/QuestDbTest/Config.cs
new file mode 100644
index 000000000..2e84a016b
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Config.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ ///
+ /// Setting up the database name does not require you to create the database
+ /// 设置好数据库名不需要你去手动建库
+ ///
+ public class Config
+ {
+ ///
+ /// Account have permission to create database
+ /// 用有建库权限的数据库账号
+ ///
+ public static string ConnectionString = "host=localhost;port=8812;username=admin;password=quest;database=qdb;ServerCompatibilityMode=NoTypeLoading;";
+ ///
+ /// Account have permission to create database
+ /// 用有建库权限的数据库账号
+ ///
+ public static string ConnectionString2 = ConnectionString;
+ ///
+ /// Account have permission to create database
+ /// 用有建库权限的数据库账号
+ ///
+ public static string ConnectionString3 = ConnectionString;
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Demo0_SqlSugarClient.cs b/Src/Asp.Net/QuestDbTest/Demo/Demo0_SqlSugarClient.cs
new file mode 100644
index 000000000..99a07216d
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Demo0_SqlSugarClient.cs
@@ -0,0 +1,424 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+namespace OrmTest
+{
+ public class Demo0_SqlSugarClient
+ {
+
+ public static void Init()
+ {
+ SqlSugarClient();//Create db
+ DbContext();//Optimizing SqlSugarClient usage
+ SingletonPattern();//Singleten Pattern
+ DistributedTransactionExample();
+ MasterSlave();//Read-write separation
+ CustomAttribute();
+ }
+
+ private static void MasterSlave()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### MasterSlave Start ####");
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ ConnectionString = Config.ConnectionString,//Master Connection
+ DbType = DbType.QuestDB,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ SlaveConnectionConfigs = new List() {
+ new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } ,
+ new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 }
+ }
+ });
+ db.Aop.OnLogExecuted = (s, p) =>
+ {
+ Console.WriteLine(db.Ado.Connection.ConnectionString);
+ };
+ Console.WriteLine("Master:");
+ db.Insertable(new Order() { Name = "abc", CustomId = 1, CreateTime = DateTime.Now }).ExecuteCommand();
+ Console.WriteLine("Slave:");
+ db.Queryable().First();
+ Console.WriteLine("#### MasterSlave End ####");
+ }
+
+ private static void SqlSugarClient()
+ {
+ //Create db
+ Console.WriteLine("#### SqlSugarClient Start ####");
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+
+ //If no exist create datebase
+ //db.DbMaintenance.CreateDatabase();
+
+ //Use db query
+ var dt = db.Ado.SqlQuery("select @id",new { id=1});
+
+ db.CodeFirst.InitTables();
+ //Create tables
+ db.CodeFirst.InitTables(typeof(OrderItem),typeof(Order));
+ //db.DbMaintenance.TruncateTable();
+ var xx=db.Insertable(new Order() { Name = "order1", CustomId = 1, Price = 0, CreateTime = DateTime.Now })
+ .ExecuteReturnSnowflakeId();
+ //Insert data
+ // db.Insertable(new OrderItem() { OrderId = id, Price = 0, CreateTime=DateTime.Now }).ExecuteCommand();
+ Console.WriteLine("#### SqlSugarClient End ####");
+
+ }
+
+ private static void DbContext()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### DbContext Start ####");
+ var insertObj = new Order { Id=SnowFlakeSingle.Instance.NextId(),Name = "jack", CreateTime = DateTime.Now };
+ var InsertObjs = new Order[] { insertObj };
+
+ DbContext context = new DbContext();
+
+ context.Db.CodeFirst.InitTables();//Create Tables
+ ;
+ var orderDb = context.OrderDb;
+
+ //Select
+ // var data1 = orderDb.GetById();
+ var data2 = orderDb.GetList();
+ var data3 = orderDb.GetList(it => it.Id == 1);
+ var data4 = orderDb.GetSingle(it => it.Id == 1);
+ var p = new PageModel() { PageIndex = 1, PageSize = 2 };
+ var data5 = orderDb.GetPageList(it => it.Name == "xx", p);
+ Console.Write(p.TotalCount);
+ var data6 = orderDb.GetPageList(it => it.Name == "xx", p, it => it.Name, OrderByType.Asc);
+ Console.Write(p.TotalCount);
+ List conModels = new List();
+ conModels.Add(new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.Equal, FieldValue = "1", FieldValueConvertFunc=it=>Convert.ToInt32(it) });//id=1
+ var data7 = orderDb.GetPageList(conModels, p, it => it.Name, OrderByType.Asc);
+ orderDb.AsQueryable().Where(x => x.Id == 1).ToList();
+
+ //Insert
+ orderDb.Insert(insertObj);
+ orderDb.InsertRange(InsertObjs);
+ var id = orderDb.InsertReturnIdentity(insertObj);
+ orderDb.AsInsertable(insertObj).ExecuteCommand();
+
+
+ ////Delete
+ //orderDb.Delete(insertObj);
+ //orderDb.DeleteById(11111);
+ //orderDb.DeleteById(new int[] { 1111, 2222 });
+ //orderDb.Delete(it => it.Id == 1111);
+ //orderDb.AsDeleteable().Where(it => it.Id == 1111).ExecuteCommand();
+
+ //Update
+ orderDb.Update(insertObj);
+ orderDb.UpdateRange(InsertObjs);
+ orderDb.Update(it => new Order() { Name = "a", }, it => it.Id == 1);
+ orderDb.AsUpdateable(insertObj).UpdateColumns(it => new { it.Name }).ExecuteCommand();
+
+ //Use Inherit DbContext
+ OrderDal dal = new OrderDal();
+ var data = dal.GetById(1);
+ var list = dal.GetList();
+
+ Console.WriteLine("#### DbContext End ####");
+ }
+
+ private static void CustomAttribute()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Custom Attribute Start ####");
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ ConnectionString = Config.ConnectionString,
+ DbType = DbType.QuestDB,
+ IsAutoCloseConnection = true,
+ InitKeyType = InitKeyType.Attribute,
+ ConfigureExternalServices = new ConfigureExternalServices()
+ {
+ EntityService = (property, column) =>
+ {
+
+ var attributes = property.GetCustomAttributes(true);//get all attributes
+
+ if (attributes.Any(it => it is KeyAttribute))// by attribute set primarykey
+ {
+ column.IsPrimarykey = true;
+ }
+ },
+ EntityNameService = (type, entity) =>
+ {
+ var attributes = type.GetCustomAttributes(true);
+ if (attributes.Any(it => it is TableAttribute))
+ {
+ entity.DbTableName = (attributes.First(it => it is TableAttribute) as TableAttribute).Name;
+ }
+ }
+ }
+ });
+ db.CodeFirst.InitTables();//Create Table
+
+ db.Insertable(new AttributeTable() { Id = Guid.NewGuid().ToString(), Name = "Name" }).ExecuteCommand();
+ var list = db.Queryable().ToList();
+
+ Console.WriteLine("#### Custom Attribute End ####");
+ }
+
+
+ private static void SingletonPattern()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Singleton Pattern Start ####");
+ Console.WriteLine("Db_Id:" + singleDb.ContextID);
+ Console.WriteLine("Db_Id:" + singleDb.ContextID);
+ var task = new Task(() =>
+ {
+ Console.WriteLine("Task DbId:" + singleDb.ContextID);
+ new Task(() =>
+ {
+ Console.WriteLine("_Task_Task DbId:" + singleDb.ContextID);
+ Console.WriteLine("_Task_Task DbId:" + singleDb.ContextID);
+
+ }).Start();
+ Console.WriteLine("Task DbId:" + singleDb.ContextID);
+ });
+ task.Start();
+ task.Wait();
+ System.Threading.Thread.Sleep(500);
+ Console.WriteLine(string.Join(",", singleDb.TempItems.Keys));
+
+ Console.WriteLine("#### Singleton Pattern end ####");
+ }
+
+ static SqlSugarScope singleDb = new SqlSugarScope(
+ new ConnectionConfig()
+ {
+ ConfigId = 1,
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents()
+ {
+ OnLogExecuting = (sql, p) => { Console.WriteLine(sql); }
+ }
+ });
+
+
+ private static void DistributedTransactionExample()
+ {
+ //Console.WriteLine("");
+ //Console.WriteLine("#### Distributed TransactionExample Start ####");
+ //SqlSugarClient db = new SqlSugarClient(new List()
+ //{
+ // new ConnectionConfig(){ ConfigId="1", DbType=DbType.QuestDB, ConnectionString=Config.ConnectionString,InitKeyType=InitKeyType.Attribute,IsAutoCloseConnection=true },
+ // new ConnectionConfig(){ ConfigId="2", DbType=DbType.QuestDB, ConnectionString=Config.ConnectionString2 ,InitKeyType=InitKeyType.Attribute ,IsAutoCloseConnection=true}
+ //});
+
+ //var db1 = db.Ado.Connection.Database;
+ ////use db1
+ //db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order), typeof(OrderItem));//
+ //db.Insertable(new Order() { Name = "order1", CreateTime = DateTime.Now }).ExecuteCommand();
+ //Console.WriteLine(db.CurrentConnectionConfig.DbType + ":" + db.Queryable().Count());
+
+ ////use db2
+ //db.ChangeDatabase("2");
+ //var db2 = db.Ado.Connection.Database;
+ //db.DbMaintenance.CreateDatabase();//Create Database2
+ //db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order), typeof(OrderItem));
+ //db.Insertable(new Order() { Name = "order1", CreateTime = DateTime.Now }).ExecuteCommand();
+ //Console.WriteLine(db.CurrentConnectionConfig.DbType + ":" + db.Queryable().Count());
+
+ //if (db2 == db1)
+ //{
+ // return;
+ //}
+ //// Example 1
+ //Console.WriteLine("Example 1");
+ //try
+ //{
+ // db.BeginTran();
+
+ // db.ChangeDatabase("1");//use db1
+ // db.Deleteable().ExecuteCommand();
+ // Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+
+ // db.ChangeDatabase("2");//use db2
+ // db.Deleteable().ExecuteCommand();
+ // Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+
+ // throw new Exception();
+ // db.CommitTran();
+ //}
+ //catch
+ //{
+ // db.RollbackTran();
+ // Console.WriteLine("---Roll back");
+ // db.ChangeDatabase("1");//use db1
+ // Console.WriteLine(db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+
+ // db.ChangeDatabase("2");//use db2
+ // Console.WriteLine(db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+ //}
+
+
+
+ //// Example 2
+ //Console.WriteLine("Example 2");
+
+ //var result=db.UseTran(() =>
+ //{
+
+ // db.ChangeDatabase("1");//use db1
+ // db.Deleteable().ExecuteCommand();
+ // Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+
+ // db.ChangeDatabase("2");//use db2
+ // db.Deleteable().ExecuteCommand();
+ // Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+ // throw new Exception("");
+
+ //});
+ //if (result.IsSuccess == false) {
+ // Console.WriteLine("---Roll back");
+ // db.ChangeDatabase("1");//use db1
+ // Console.WriteLine(db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+
+ // db.ChangeDatabase("2");//use db2
+ // Console.WriteLine(db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+ //}
+
+ //// Example 3
+ //Console.WriteLine("Example 3");
+
+ //var result2 = db.UseTranAsync(async () =>
+ //{
+
+ // db.ChangeDatabase("1");//use db1
+ // await db.Deleteable().ExecuteCommandAsync();
+ // Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+
+ // db.ChangeDatabase("2");//use db2
+ // await db.Deleteable().ExecuteCommandAsync();
+ // Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+ // throw new Exception("");
+
+ //});
+ //result2.Wait();
+ //if (result2.Result.IsSuccess == false)
+ //{
+ // Console.WriteLine("---Roll back");
+ // db.ChangeDatabase("1");//use sqlserver
+ // Console.WriteLine(db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+
+ // db.ChangeDatabase("2");//use mysql
+ // Console.WriteLine(db.CurrentConnectionConfig.DbType);
+ // Console.WriteLine(db.Queryable().Count());
+ //}
+
+ Console.WriteLine("#### Distributed TransactionExample End ####");
+ }
+ }
+
+ ///
+ /// DbContext Example 1
+ ///
+ public class DbContext
+ {
+
+ public SqlSugarClient Db;
+ public DbContext()
+ {
+ Db = new SqlSugarClient(new ConnectionConfig()
+ {
+ ConnectionString = Config.ConnectionString,
+ DbType = DbType.QuestDB,
+ IsAutoCloseConnection = true,
+ InitKeyType = InitKeyType.Attribute,
+ AopEvents = new AopEvents()
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ }
+ }
+ });
+ }
+ public SimpleClient OrderDb => new SimpleClient(Db);
+ public SimpleClient OrderItemDb => new SimpleClient(Db);
+ }
+
+
+ public class OrderDal : DbContext
+ {
+
+ }
+ ///
+ /// DbContext Example 2
+ ///
+ ///
+ public class DbContext where T : class, new()
+ {
+
+ public SqlSugarClient Db;
+ public DbContext()
+ {
+ Db = new SqlSugarClient(new ConnectionConfig()
+ {
+ ConnectionString = Config.ConnectionString,
+ DbType = DbType.QuestDB,
+ IsAutoCloseConnection = true,
+ InitKeyType = InitKeyType.Attribute,
+ AopEvents = new AopEvents()
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ }
+ }
+ });
+ }
+ public SimpleClient CurrentDb => new SimpleClient(Db);
+ public virtual T GetById(int id)
+ {
+ return CurrentDb.GetById(id);
+ }
+ public virtual List GetList()
+ {
+ return CurrentDb.GetList();
+ }
+ public virtual bool Delete(int id)
+ {
+ return CurrentDb.DeleteById(id);
+ }
+ }
+
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Demo1_Queryable.cs b/Src/Asp.Net/QuestDbTest/Demo/Demo1_Queryable.cs
new file mode 100644
index 000000000..a9ef73255
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Demo1_Queryable.cs
@@ -0,0 +1,334 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Dynamic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest
+{
+ public class Demo1_Queryable
+ {
+
+ public static void Init()
+ {
+ EasyExamples();
+ QueryConditions();
+ JoinTable();
+ Async();
+ NoEntity();
+ SqlFuncTest();
+ ReturnType();
+ }
+
+ private static void EasyExamples()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Examples Start ####");
+ var db = GetInstance();
+ var dbTime = db.GetDate();
+ var getAll = db.Queryable().ToList();
+ var getLike = db.Queryable().Where(it=>it.Name.Contains("order1")).ToList();
+ var getYYYY = db.Queryable().Select(it => it.CreateTime.ToString("yyyy-MM-dd")).ToList();
+ var getOrderBy = db.Queryable().OrderBy(it => it.Name,OrderByType.Desc).ToList();
+ var getOrderBy2 = db.Queryable().OrderBy(it => it.Id).OrderBy(it => it.Name, OrderByType.Desc).ToList();
+ var getOrderBy3 = db.Queryable().OrderBy(it =>new { it.Name,it.Id}).ToList();
+ //var getRandom = db.Queryable().OrderBy(it => SqlFunc.GetRandom()).First();
+ var getSingleOrDefault = db.Queryable().Where(it => it.Id == 1).Single();
+ var getFirstOrDefault = db.Queryable().First();
+ var getByWhere = db.Queryable().Where(it => it.Id == 1 || it.Name == "a").ToList();
+ var getByWhere2 = db.Queryable().Where(it => it.Id == DateTime.Now.Year).ToList();
+ var getByFuns = db.Queryable().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList();
+ // var getByFuns2 = db.Queryable().GroupBy(it => it.Name).Select(it => SqlFunc.AggregateDistinctCount(it.Price)).ToList();
+ var btime = Convert.ToDateTime("2021-1-1");
+ var etime = Convert.ToDateTime("2022-1-12");
+ var test01 = db.Queryable().Select(it => SqlFunc.DateDiff(DateType.Year,btime, etime)).ToList();
+ var test02 = db.Queryable().Select(it => SqlFunc.DateDiff(DateType.Day, btime, etime)).ToList();
+ var test03 = db.Queryable().Select(it => SqlFunc.DateDiff(DateType.Month, btime, etime)).ToList();
+ //var test04 = db.Queryable().Select(it => SqlFunc.DateDiff(DateType.Second, DateTime.Now, DateTime.Now.AddMinutes(2))).ToList();
+ var q1 = db.Queryable().Take(1);
+ var q2 = db.Queryable().Take(2);
+ var test05 = db.UnionAll(q1, q2).ToList();
+ var test06 = db.Queryable().ToList();
+
+ if (db.DbMaintenance.IsAnyTable("users", false))
+ {
+ db.DbMaintenance.DropTable("users");
+ }
+ if (!db.DbMaintenance.IsAnyTable("users", false))
+ {
+ db.CodeFirst.InitTables();
+ }
+
+ var list = new List();
+ for (var i = 0; i < 1000; i++)
+ {
+
+ list.Add(new Users
+ {
+ Sid=SnowFlakeSingle.Instance.NextId(),
+ createtime = DateTime.Now,
+ username = "161718",
+ password = "161718",
+ });
+ }
+ db.Insertable(list).ExecuteCommand();
+
+ var list2 = db.Queryable().ToList();
+
+ Console.WriteLine("#### Examples End ####");
+ Console.WriteLine("#### Examples End ####");
+ }
+
+ private static void ReturnType()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### ReturnType Start ####");
+ var db = GetInstance();
+ List list = db.Queryable().ToList();
+
+ Order item = db.Queryable().First(it => it.Id == 1);
+
+ DataTable dataTable = db.Queryable().Select(it => it.Id).ToDataTable();
+
+ var json = db.Queryable().ToJson();
+
+ List listInt = db.Queryable().Select(it => it.Id).ToList();
+
+ var dynamic = db.Queryable().Select().ToList();
+
+ var viewModel = db.Queryable((o, i, c) => new JoinQueryInfos(
+ JoinType.Left, o.Id == i.OrderId ,
+ JoinType.Left, o.CustomId == c.Id
+ ))
+ .Select().ToList();
+
+ var newDynamic = db.Queryable((o, i, c) => new JoinQueryInfos(
+ JoinType.Left, o.Id == i.OrderId,
+ JoinType.Left, o.CustomId == c.Id
+ ))
+ .Select((o, i, c) => new { orderName = o.Name, cusName=c.Name }).ToList();
+
+ var newClass = db.Queryable((o, i, c) => new JoinQueryInfos(
+ JoinType.Left, o.Id == i.OrderId,
+ JoinType.Left, o.CustomId == c.Id
+ ))
+ .Select((o, i, c) => new ViewOrder { Name=o.Name, CustomName=c.Name }).ToList();
+
+
+ var oneClass = db.Queryable((o, i, c) => new JoinQueryInfos(
+ JoinType.Left, o.Id == i.OrderId,
+ JoinType.Left, o.CustomId == c.Id
+ ))
+ .Select((o, i, c) => c).ToList();
+
+ var twoClass = db.Queryable((o, i, c) => new JoinQueryInfos(
+ JoinType.Left, o.Id == i.OrderId,
+ JoinType.Left, o.CustomId == c.Id
+ ))
+ .Select((o, i, c) => new { o,i}).ToList();
+
+ List> ListDic = db.Queryable((o, i, c) => new JoinQueryInfos(
+ JoinType.Left, o.Id == i.OrderId,
+ JoinType.Left, o.CustomId == c.Id
+ ))
+ .Select().ToList().Select(it => it.ToDictionary(x => x.Key, x => x.Value)).ToList();
+ Console.WriteLine("#### ReturnType End ####");
+ }
+
+
+ private static void SqlFuncTest()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### SqlFunc Start ####");
+ var db = GetInstance();
+ var index= db.Queryable().Select(it => SqlFunc.Contains("a", "cccacc")).First();
+ //var list = db.Queryable().Select(it => new ViewOrder()
+ //{
+
+ // Id = SqlFunc.AggregateSum(SqlFunc.IF(it.Id > 0).Return(1).End(0))
+ //}).ToList();
+ var list2 = db.Queryable().Select(it => new
+ {
+ date = SqlFunc.ToDateShort(it.CreateTime),
+ datetime = SqlFunc.ToDate(it.CreateTime)
+ }).ToList();
+ Console.WriteLine("#### SqlFunc End ####");
+ }
+
+
+ private static void NoEntity()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### No Entity Start ####");
+ var db = GetInstance();
+
+ var list = db.Queryable().AS("order_1").Where("id=id", new { id = 1 }).ToList();
+
+ var list2 = db.Queryable("o").AS("order_1").AddJoinInfo("OrderDetail_1", "i", "o.id=i.OrderId").Where("id=id", new { id = 1 }).Select("o.*").ToList();
+ Console.WriteLine("#### No Entity End ####");
+ }
+
+ private static void JoinTable()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Join Table Start ####");
+ var db = GetInstance();
+
+ //Simple join
+ var list = db.Queryable((o, i, c) => o.Id == i.OrderId&&c.Id == o.CustomId)
+ .Select()
+ .ToList();
+
+ //Join table
+ var list2 = db.Queryable((o, i, c) => new JoinQueryInfos(
+ JoinType.Left, o.Id == i.OrderId,
+ JoinType.Left, c.Id == o.CustomId
+ ))
+ .Select().ToList();
+
+ //Join queryable
+ var query1 = db.Queryable((o, i) => new JoinQueryInfos(
+ JoinType.Left, o.Id == i.OrderId
+ ))
+ .Where(o => o.Name == "jack");
+
+ var query2 = db.Queryable();
+ var list3=db.Queryable(query1, query2,JoinType.Left, (p1, p2) => p1.CustomId == p2.Id).Select().ToList();
+
+ Console.WriteLine("#### Join Table End ####");
+ }
+
+ private static void QueryConditions()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Query Conditions Start ####");
+
+ SqlSugarClient db = GetInstance();
+
+ /*** By expression***/
+
+ //id=@id
+ var list = db.Queryable().Where(it => it.Id == 1).ToList();
+ //id=@id or name like '%'+@name+'%'
+ var list2 = db.Queryable().Where(it => it.Id == 1 || it.Name.Contains("jack")).ToList();
+
+
+ //Create expression
+ var exp = Expressionable.Create()
+ .And(it => it.Id == 1)
+ .Or(it => it.Name.Contains("jack")).ToExpression();
+ var list3 = db.Queryable().Where(exp).ToList();
+
+
+ /*** By sql***/
+
+ //id=@id
+ var list4 = db.Queryable().Where("id=@id", new { id = 1 }).ToList();
+ //id=@id or name like '%'+@name+'%'
+ var list5 = db.Queryable().Where("id=@id or name like @name ", new { id = 1, name = "%jack%" }).ToList();
+
+
+
+ /*** By dynamic***/
+
+ //id=1
+ var conModels = new List();
+ conModels.Add(new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.Equal, FieldValue = "1" , FieldValueConvertFunc=it=>Convert.ToInt32(it) });//id=1
+ var student = db.Queryable().Where(conModels).ToList();
+
+ //Complex use case
+ List Order = new List();
+ conModels.Add(new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.Equal, FieldValue = "1", FieldValueConvertFunc = it => Convert.ToInt32(it) });//id=1
+ //conModels.Add(new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.Like, FieldValue = "1", FieldValueConvertFunc = it => Convert.ToInt32(it) });// id like '%1%'
+ //conModels.Add(new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.IsNullOrEmpty });
+ //conModels.Add(new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.In, FieldValue = "1,2,3" });
+ //conModels.Add(new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.NotIn, FieldValue = "1,2,3" });
+ //conModels.Add(new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.NoEqual, FieldValue = "1,2,3" });
+ //conModels.Add(new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.IsNot, FieldValue = null });// id is not null
+
+ conModels.Add(new ConditionalCollections()
+ {
+ ConditionalList = new List>()// (id=1 or id=2 and id=1)
+ {
+ //new KeyValuePair( WhereType.And ,new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.Equal, FieldValue = "1" }),
+ new KeyValuePair (WhereType.Or,new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.Equal, FieldValue = "2" , FieldValueConvertFunc = it => Convert.ToInt32(it) }),
+ new KeyValuePair ( WhereType.And,new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.Equal, FieldValue = "2" ,FieldValueConvertFunc = it => Convert.ToInt32(it)})
+ }
+ });
+ var list6 = db.Queryable().Where(conModels).ToList();
+
+ /*** Conditional builder ***/
+
+ // use whereif
+ string name = "";
+ int id = 1;
+ var query = db.Queryable()
+ .WhereIF(!string.IsNullOrEmpty(name), it => it.Name.Contains(name))
+ .WhereIF(id > 0, it => it.Id == id).ToList();
+ //clone new Queryable
+ var query2 = db.Queryable().Where(it => it.Id == 1);
+ var list7 = query2.Clone().Where(it => it.Name == "jack").ToList();//id=1 and name = jack
+ var list8 = query2.Clone().Where(it => it.Name == "tom").ToList();//id=1 and name = tom
+ db.CodeFirst.InitTables();
+ //无限级高性能导航映射
+ var treeRoot = db.Queryable().Where(it => it.Id == 1).ToList();
+ db.ThenMapper(treeRoot, item =>
+ {
+ item.Child = db.Queryable().SetContext(x => x.ParentId, () => item.Id, item).ToList();
+ });
+ db.ThenMapper(treeRoot.SelectMany(it => it.Child), it =>
+ {
+ it.Child = db.Queryable().SetContext(x => x.ParentId, () => it.Id, it).ToList();
+ });
+ db.ThenMapper(treeRoot.SelectMany(it => it.Child).SelectMany(it => it.Child), it =>
+ {
+ it.Child = db.Queryable().SetContext(x => x.ParentId, () => it.Id, it).ToList();
+ });
+ db.ThenMapper(treeRoot.SelectMany(it => it.Child).SelectMany(it => it.Child).SelectMany(it => it.Child), it =>
+ {
+ it.Child = db.Queryable().SetContext(x => x.ParentId, () => it.Id, it).ToList();
+ });
+ Console.WriteLine("#### Condition Screening End ####");
+
+
+
+ }
+
+ private static void Async()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Async Start ####");
+
+ SqlSugarClient db = GetInstance();
+ var task1 = db.Queryable().FirstAsync();
+ task1.Wait();
+ var task2 = db.Queryable().Where(it => it.Id == 1).ToListAsync();
+
+
+ task2.Wait();
+
+ Console.WriteLine("#### Async End ####");
+ }
+
+ private static SqlSugarClient GetInstance()
+ {
+ return new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = SqlSugar.DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Demo2_Updateable.cs b/Src/Asp.Net/QuestDbTest/Demo/Demo2_Updateable.cs
new file mode 100644
index 000000000..0014b7452
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Demo2_Updateable.cs
@@ -0,0 +1,110 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class Demo2_Updateable
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Updateable Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+
+
+
+ /*** 1.entity or List ***/
+
+ var updateObj = new Order() { Id = 1, Name = "order1" };
+ var updateObjs = new List {
+ new Order() { Id = 11, Name = "order11",CreateTime=DateTime.Now },
+ new Order() { Id = 12, Name = "order12" ,CreateTime=DateTime.Now}
+ };
+
+ //update all columns by primary key
+ var result = db.Updateable(updateObj).ExecuteCommand();//update single
+ var result2 = db.Updateable(updateObjs).ExecuteCommand();//update List
+
+ //Ignore Name and Price
+ var result3 = db.Updateable(updateObj).IgnoreColumns(it => new { it.CreateTime, it.Price }).ExecuteCommand();
+
+ //only update Name and CreateTime
+ var result4 = db.Updateable(updateObj).UpdateColumns(it => new { it.Name, it.CreateTime }).ExecuteCommand();
+
+ //If there is no primary key
+ var result5 = db.Updateable(updateObj).WhereColumns(it => new { it.Id }).ExecuteCommand();//update single by id
+ var result6 = db.Updateable(updateObjs).WhereColumns(it => new { it.Id }).ExecuteCommand();//update List by id
+
+
+
+
+ /*** 2.by expression ***/
+
+ //update name,createtime
+ var result7 = db.Updateable(it => new Order() { Name = "a", CreateTime = DateTime.Now }).Where(it => it.Id == 11).ExecuteCommand();
+ var result71 = db.Updateable().SetColumns(it => new Order() { Name = "a", CreateTime = DateTime.Now }).Where(it => it.Id == 11).ExecuteCommand();
+ //only update name
+ var result8 = db.Updateable(it => it.Name == "Name").Where(it => it.Id == 1).ExecuteCommand();
+ var result81 = db.Updateable()
+ .SetColumns(it => it.Name == "Name" )
+ .SetColumns(it => it.CreateTime == DateTime.Now)
+ .Where(it => it.Id == 1).ExecuteCommand();
+ //
+
+
+
+
+ /*** 3.by Dictionary ***/
+ var dt = new Dictionary();
+ dt.Add("id", 1);
+ dt.Add("name", "abc");
+ dt.Add("createTime", DateTime.Now);
+ var dtList = new List>();
+ dtList.Add(dt);
+
+ var t66 = db.Updateable(dt).AS("order_1").WhereColumns("id").ExecuteCommand();
+ var t666 = db.Updateable(dtList).AS("order_1").WhereColumns("id").ExecuteCommand();
+
+
+
+ /*** 4.Other instructions ***/
+
+ var caseValue = "1";
+ //Do not update NULL columns
+ db.Updateable(updateObj).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
+
+ //if 1 update name else if 2 update name,createtime
+ db.Updateable(updateObj)
+ .UpdateColumnsIF(caseValue == "1", it => new { it.Name })
+ .UpdateColumnsIF(caseValue == "2", it => new { it.Name, it.CreateTime })
+ .ExecuteCommand();
+ //Use Lock
+ db.Updateable(updateObj).With(SqlWith.UpdLock).ExecuteCommand();
+
+ //Where Sql
+ //db.Updateable(updateObj).Where("id=@x", new { x = 1 }).ExecuteCommand();
+
+ Console.WriteLine("#### Updateable End ####");
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Demo3_Insertable.cs b/Src/Asp.Net/QuestDbTest/Demo/Demo3_Insertable.cs
new file mode 100644
index 000000000..e8fcfbff8
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Demo3_Insertable.cs
@@ -0,0 +1,63 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class Demo3_Insertable
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Insertable Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+
+ var insertObj = new Order() { Id = 1, Name = "order1",Price=0 ,Value = 10.133};
+ var updateObjs = new List {
+ new Order() { Id = SnowFlakeSingle.Instance.NextId(), Name = "order11", Price=0 ,Value = 0.242},
+ new Order() { Id = SnowFlakeSingle.Instance.NextId(), Name = "order12" , Price=0,Value = 3.343}
+ };
+
+ var x = db.Insertable(updateObjs).RemoveDataCache().IgnoreColumns(it => it.CreateTime).UseParameter().ExecuteCommand();
+
+ //Ignore CreateTime
+ db.Insertable(insertObj).IgnoreColumns(it => new { it.CreateTime }).ExecuteReturnSnowflakeId();//get identity
+ db.Insertable(insertObj).IgnoreColumns("CreateTime").ExecuteReturnSnowflakeId();
+
+ //Only insert Name and Price
+ db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.Price }).ExecuteReturnSnowflakeId();
+ db.Insertable(insertObj).InsertColumns("Name", "Price").ExecuteReturnSnowflakeId();
+
+ foreach (var item in updateObjs)
+ {
+ item.Id = 0;
+ }
+ //ignore null columns
+ db.Insertable(updateObjs).ExecuteReturnSnowflakeId();//get change row count
+
+ //Use Lock
+ db.Insertable(insertObj).With(SqlWith.UpdLock).ExecuteReturnSnowflakeId();
+
+
+ Console.WriteLine("#### Insertable End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Demo4_Deleteable.cs b/Src/Asp.Net/QuestDbTest/Demo/Demo4_Deleteable.cs
new file mode 100644
index 000000000..871b25ef4
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Demo4_Deleteable.cs
@@ -0,0 +1,48 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class Demo4_Deleteable
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Deleteable Start ####");
+ //No Support DELETE
+ //SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ //{
+ // DbType = DbType.QuestDB,
+ // ConnectionString = Config.ConnectionString,
+ // InitKeyType = InitKeyType.Attribute,
+ // IsAutoCloseConnection = true,
+ // AopEvents = new AopEvents
+ // {
+ // OnLogExecuting = (sql, p) =>
+ // {
+ // Console.WriteLine(sql);
+ // Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ // }
+ // }
+ //});
+ ////by entity
+ //db.Deleteable().Where(new Order() { Id = 1111 }).ExecuteCommand();
+
+ ////by primary key
+ //db.Deleteable().In(1111).ExecuteCommand();
+
+ ////by primary key array
+ //db.Deleteable().In(new int[] { 1111, 2222 }).ExecuteCommand();
+
+ ////by expression
+ //db.Deleteable().Where(it => it.Id == 11111).ExecuteCommand();
+
+ Console.WriteLine("#### Deleteable End ####");
+
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Demo5_SqlQueryable.cs b/Src/Asp.Net/QuestDbTest/Demo/Demo5_SqlQueryable.cs
new file mode 100644
index 000000000..b2442b714
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Demo5_SqlQueryable.cs
@@ -0,0 +1,36 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class Demo5_SqlQueryable
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### SqlQueryable Start ####");
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true
+ });
+
+ int total = 0;
+ var list = db.SqlQueryable("select * from \"order_1\"").ToPageList(1, 2, ref total);
+
+
+ //by expression
+ var list2 = db.SqlQueryable("select * from \"order_1\"").Where(it => it.Id == 1).ToPageList(1, 2);
+ //by sql
+ var list3 = db.SqlQueryable("select * from \"order_1\"").Where("id=@id", new { id = 1 }).ToPageList(1, 2);
+
+ Console.WriteLine("#### SqlQueryable End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Demo6_Queue.cs b/Src/Asp.Net/QuestDbTest/Demo/Demo6_Queue.cs
new file mode 100644
index 000000000..c8bf0f8ad
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Demo6_Queue.cs
@@ -0,0 +1,52 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class Demo6_Queue
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Queue Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+ db.Insertable(new Order() { Name = "a" }).AddQueue();
+ db.Insertable(new Order() { Name = "b" }).AddQueue();
+ db.SaveQueues();
+
+
+ db.Insertable(new Order() { Name = "a" }).AddQueue();
+ db.Insertable(new Order() { Name = "b" }).AddQueue();
+ db.Insertable(new Order() { Name = "c" }).AddQueue();
+ db.Insertable(new Order() { Name = "d" }).AddQueue();
+ var ar = db.SaveQueuesAsync();
+ ar.Wait();
+
+ db.Queryable().AddQueue();
+ db.Queryable().AddQueue();
+ db.AddQueue("select * from \"order\" where id=@id", new { id = 10000 });
+ var result2 = db.SaveQueues();
+
+ Console.WriteLine("#### Queue End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Demo7_Ado.cs b/Src/Asp.Net/QuestDbTest/Demo/Demo7_Ado.cs
new file mode 100644
index 000000000..4f0a6579f
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Demo7_Ado.cs
@@ -0,0 +1,57 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class Demo7_Ado
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Ado Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+ //sql
+ var dt = db.Ado.GetDataTable("select * from \"order_1\" where @id>0 or name=@name", new List(){
+ new SugarParameter("@id",1),
+ new SugarParameter("@name","2")
+ });
+
+ //sql
+ var dt2 = db.Ado.GetDataTable("select * from \"order_1\" where @id>0 or name=@name", new { id = 1, name = "2" });
+
+ //Stored Procedure
+ //var dt3 = db.Ado.UseStoredProcedure().GetDataTable("sp_school", new { name = "张三", age = 0 });
+ //var nameP = new SugarParameter("@name", "张三");
+ //var ageP = new SugarParameter("@age", null, true);//isOutput=true
+ //var dt4 = db.Ado.UseStoredProcedure().GetDataTable("sp_school", nameP, ageP);
+
+
+
+ //There are many methods to under db.ado
+ var list= db.Ado.SqlQuery("select * from \"order_1\" ");
+ var intValue=db.Ado.SqlQuerySingle("select 1");
+ //db.Ado.ExecuteCommand("delete from \"order\" where id>1000");
+ //db.Ado.xxx
+ Console.WriteLine("#### Ado End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Demo8_Saveable.cs b/Src/Asp.Net/QuestDbTest/Demo/Demo8_Saveable.cs
new file mode 100644
index 000000000..3914269c5
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Demo8_Saveable.cs
@@ -0,0 +1,48 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class Demo8_Saveable
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Saveable Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+
+
+ ////insert or update
+ //db.Saveable(new Order() { Id=1, Name="jack" }).ExecuteReturnEntity();
+
+
+ ////insert or update
+ //db.Saveable(new Order() { Id = 1000, Name = "jack", CreateTime=DateTime.Now })
+ // .InsertColumns(it => new { it.Name,it.CreateTime, it.Price})//if insert into name,CreateTime,Price
+ // .UpdateColumns(it => new { it.Name, it.CreateTime })//if update set name CreateTime
+ // .ExecuteReturnEntity();
+
+ Console.WriteLine("");
+ Console.WriteLine("#### Saveable End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Demo9_EntityMain.cs b/Src/Asp.Net/QuestDbTest/Demo/Demo9_EntityMain.cs
new file mode 100644
index 000000000..466cfdd54
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Demo9_EntityMain.cs
@@ -0,0 +1,46 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class Demo9_EntityMain
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### EntityMain Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+ var entityInfo = db.EntityMaintenance.GetEntityInfo();
+ foreach (var column in entityInfo.Columns)
+ {
+ Console.WriteLine(column.DbColumnName);
+ }
+
+ var dbColumnsName = db.EntityMaintenance.GetDbColumnName("Name");
+
+ var dbTableName = db.EntityMaintenance.GetTableName();
+
+ //more https://github.com/sunkaixuan/SqlSugar/wiki/9.EntityMain
+ Console.WriteLine("#### EntityMain End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/DemoA_DbMain.cs b/Src/Asp.Net/QuestDbTest/Demo/DemoA_DbMain.cs
new file mode 100644
index 000000000..a62eece6a
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/DemoA_DbMain.cs
@@ -0,0 +1,42 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class DemoA_DbMain
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### DbMain Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+
+ var tables = db.DbMaintenance.GetTableInfoList();
+ foreach (var table in tables)
+ {
+ Console.WriteLine(table.Description);
+ }
+ //more https://github.com/sunkaixuan/SqlSugar/wiki/a.DbMain
+ Console.WriteLine("#### DbMain End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/DemoB_Aop.cs b/Src/Asp.Net/QuestDbTest/Demo/DemoB_Aop.cs
new file mode 100644
index 000000000..e687c6e3d
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/DemoB_Aop.cs
@@ -0,0 +1,68 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class DemoB_Aop
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Aop Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true
+ });
+ db.Aop.OnLogExecuted = (sql, pars) => //SQL executed event
+ {
+ Console.WriteLine("OnLogExecuted" + sql);
+ };
+ db.Aop.OnLogExecuting = (sql, pars) => //SQL executing event (pre-execution)
+ {
+ Console.WriteLine("OnLogExecuting" + sql);
+ };
+ db.Aop.OnError = (exp) =>//SQL execution error event
+ {
+ //exp.sql
+ };
+ db.Aop.OnExecutingChangeSql = (sql, pars) => //SQL executing event (pre-execution,SQL script can be modified)
+ {
+ return new KeyValuePair(sql, pars);
+ };
+ db.Aop.OnDiffLogEvent = it =>//Get data changes
+ {
+ var editBeforeData = it.BeforeData;
+ var editAfterData = it.AfterData;
+ var sql = it.Sql;
+ var parameter = it.Parameters;
+ var businessData = it.BusinessData;
+ var time = it.Time;
+ var diffType = it.DiffType;//enum insert 、update and delete
+ //Console.WriteLine(businessData);
+ //Console.WriteLine(editBeforeData[0].Columns[1].Value);
+ //Console.WriteLine("to");
+ //Console.WriteLine(editAfterData[0].Columns[1].Value);
+ //Write logic
+ };
+
+
+ db.Queryable().ToList();
+ db.Queryable().ToList();
+
+ //OnDiffLogEvent
+ var data = db.Queryable().First();
+ data.Name = "changeName";
+ db.Updateable(data).EnableDiffLogEvent("--update Order--").ExecuteCommand();
+ db.Insertable(data).EnableDiffLogEvent("--inser Order--").ExecuteCommand();
+ Console.WriteLine("#### Aop End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/DemoD_DbFirst.cs b/Src/Asp.Net/QuestDbTest/Demo/DemoD_DbFirst.cs
new file mode 100644
index 000000000..3361c87d7
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/DemoD_DbFirst.cs
@@ -0,0 +1,78 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest
+{
+ public class DemoD_DbFirst
+ {
+ public static void Init()
+ {
+ Console.WriteLine();
+ Console.WriteLine("#### DbFirst Start ####");
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ MoreSettings=new ConnMoreSettings() {
+ PgSqlIsAutoToLower=false
+ }
+ });
+
+ db.DbFirst.CreateClassFile("c:\\Demo\\1", "Models");
+
+
+ db.DbFirst.Where("Student").CreateClassFile("c:\\Demo\\2", "Models");
+
+
+ db.DbFirst.Where(it => it.ToLower().StartsWith("view")).CreateClassFile("c:\\Demo\\3", "Models");
+
+
+ db.DbFirst.Where(it => it.ToLower().StartsWith("view")).CreateClassFile("c:\\Demo\\4", "Models");
+
+
+ db.DbFirst.IsCreateAttribute().CreateClassFile("c:\\Demo\\5", "Models");
+
+
+ db.DbFirst.IsCreateDefaultValue().CreateClassFile("c:\\Demo\\6", "Demo.Models");
+
+
+ db.DbFirst. SettingClassTemplate(old => { return old;})
+ .SettingNamespaceTemplate(old =>{ return old;})
+ .SettingPropertyDescriptionTemplate(old =>
+ {
+ return @" ///
+ /// Desc_New:{PropertyDescription}
+ /// Default_New:{DefaultValue}
+ /// Nullable_New:{IsNullable}
+ /// ";
+ })
+ .SettingPropertyTemplate(old =>{return old;})
+ .SettingConstructorTemplate(old =>{return old; })
+ .CreateClassFile("c:\\Demo\\7");
+
+
+
+ foreach (var item in db.DbMaintenance.GetTableInfoList())
+ {
+ string entityName = item.Name.ToUpper();/*Format class name*/
+ db.MappingTables.Add(entityName , item.Name);
+ foreach (var col in db.DbMaintenance.GetColumnInfosByTableName(item.Name))
+ {
+ db.MappingColumns.Add(col.DbColumnName.ToUpper() /*Format class property name*/, col.DbColumnName, entityName);
+ }
+ }
+ db.DbFirst.IsCreateAttribute().CreateClassFile("c:\\Demo\\8", "Models");
+
+
+ //Use Razor Template
+ //db.DbFirst.UseRazorAnalysis(RazorFirst.DefaultRazorClassTemplate).CreateClassFile("");
+
+ Console.WriteLine("#### DbFirst End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/DemoE_CodeFirst.cs b/Src/Asp.Net/QuestDbTest/Demo/DemoE_CodeFirst.cs
new file mode 100644
index 000000000..bd7e79fbe
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/DemoE_CodeFirst.cs
@@ -0,0 +1,100 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest
+{
+ public class DemoE_CodeFirst
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### CodeFirst Start ####");
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString3,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true
+ });
+ db.Aop.OnLogExecuting = (s, p) =>
+ {
+ Console.WriteLine(s);
+ };
+ db.DbMaintenance.CreateDatabase();
+ db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1
+ db.Insertable(new CodeFirstTable1() { Name = "a", Text = "a" }).ExecuteCommand();
+ var list = db.Queryable().ToList();
+ db.CodeFirst.InitTables();
+ db.CodeFirst.InitTables();
+ TestBool(db);
+ TestGuid(db);
+ Console.WriteLine("#### CodeFirst end ####");
+ }
+ private static void TestGuid(SqlSugarClient db)
+ {
+ db.CodeFirst.InitTables();
+ //db.DbMaintenance.TruncateTable("BoolTest");
+ var Id =SnowFlakeSingle.Instance.NextId();
+ db.Insertable(new GuidTest() { A = Guid.Empty, Id = Id }).ExecuteCommand();
+ Console.Write(db.Queryable().First().A);
+ db.Updateable(new GuidTest() { A = Guid.NewGuid(), Id = Id }).ExecuteCommand();
+ Console.Write(db.Queryable().First().A);
+ }
+ private static void TestBool(SqlSugarClient db)
+ {
+ db.CodeFirst.InitTables();
+ //db.DbMaintenance.TruncateTable("BoolTest3");
+ var Id = SnowFlakeSingle.Instance.NextId();
+ db.Insertable(new List(){ new BoolTest5() { dateTime=DateTime.Now,A = true, Id = Id } }).ExecuteCommand();
+ Console.Write(db.Queryable().First(it=>it.Id==Id).A);
+ //db.Updateable(new BoolTest4() { dateTime = DateTime.Now,A = false, Id = Id }).ExecuteCommand();
+ db.Updateable( new BoolTest5() { dateTime = DateTime.Now, A = false, Id = Id }).ExecuteCommand();
+ Console.Write(db.Queryable().First(it => it.Id == Id).A);
+ }
+ }
+ public class GuidTest
+ {
+ [SugarColumn(IsPrimaryKey = true)]
+ public long Id { get; set; }
+ public Guid A { get; set; }
+ }
+ public class BoolTest5
+ {
+ [SugarColumn(IsPrimaryKey = true)]
+ public long Id { get; set; }
+ public bool A { get; set; }
+ public DateTime dateTime { get; set; }
+ }
+
+ [SugarIndex(null, nameof(IndexClass.Name), OrderByType.Asc)]
+ public class IndexClass
+ {
+ public int Id { get; set; }
+ [SugarColumn(ColumnDataType = "symbol")]
+ public string Name { get; set; }
+ }
+
+
+
+ public class SplitTableEntity
+ {
+ public string Id { get; set; }
+ [TimeDbSplitField(DateType.Day)]
+ public DateTime Ts { get; set; }
+ }
+
+
+ public class CodeFirstTable1
+ {
+ [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ [SugarColumn(ColumnDataType = "string")]//custom
+ public string Text { get; set; }
+ [SugarColumn(IsNullable = true)]
+ public DateTime CreateTime { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/DemoF_Utilities.cs b/Src/Asp.Net/QuestDbTest/Demo/DemoF_Utilities.cs
new file mode 100644
index 000000000..0af3e9ce9
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/DemoF_Utilities.cs
@@ -0,0 +1,46 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class DemoF_Utilities
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Utilities Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+
+
+ List ids = Enumerable.Range(1, 100).ToList();
+ db.Utilities.PageEach(ids, 10, list =>
+ {
+ Console.WriteLine(string.Join("," ,list));
+ });
+
+ var list2= db.Utilities.DataTableToList(db.Ado.GetDataTable("select * from \"order_1\""));
+
+ //more https://github.com/sunkaixuan/SqlSugar/wiki/f.Utilities
+ Console.WriteLine("#### Utilities End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/DemoG_SimpleClient.cs b/Src/Asp.Net/QuestDbTest/Demo/DemoG_SimpleClient.cs
new file mode 100644
index 000000000..d98613fba
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/DemoG_SimpleClient.cs
@@ -0,0 +1,36 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class DemoG_SimpleClient
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### SimpleClient Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+
+ Console.WriteLine("#### SimpleClient End ####");
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/DemoH_Snowflake.cs b/Src/Asp.Net/QuestDbTest/Demo/DemoH_Snowflake.cs
new file mode 100644
index 000000000..1a06aebe3
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/DemoH_Snowflake.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PgSqlTest.Demo
+{
+ class DemoH_Snowflake
+ {
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Demo/DemoJ_Report.cs b/Src/Asp.Net/QuestDbTest/Demo/DemoJ_Report.cs
new file mode 100644
index 000000000..f4bab1c88
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/DemoJ_Report.cs
@@ -0,0 +1,141 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class DemoJ_Report
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Utilities Start ####");
+
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
+ {
+ DbType = DbType.QuestDB,
+ ConnectionString = Config.ConnectionString,
+ InitKeyType = InitKeyType.Attribute,
+ IsAutoCloseConnection = true,
+ AopEvents = new AopEvents
+ {
+ OnLogExecuting = (sql, p) =>
+ {
+ Console.WriteLine(sql);
+ Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
+ }
+ }
+ });
+ Demo1(db);
+ Demo2(db);
+ Demo3(db);
+ }
+
+ private static void Demo1(SqlSugarClient db)
+ {
+ var list = new List() { 1, 2, 3 };
+ var query1 = db.Queryable();
+ var queryable2 = db.Reportable(list).ToQueryable();
+ var x = db.Queryable(queryable2, query1, (x2, x1) => x1.Id.Equals(x2.ColumnName))
+ .Select((x2, x1) => new { x = x1.Id, x2 = x2.ColumnName }).ToList();
+ }
+ private static void Demo2(SqlSugarClient db)
+ {
+ var list = db.Queryable().ToList();
+ var query1 = db.Queryable();
+ var queryable2 = db.Reportable(list).ToQueryable();
+ var x = db.Queryable(query1, queryable2, (x1, x2) => x1.Id.Equals(x2.OrderId))
+ .Select((x1, x2) => new { name = x1.Name,id=x1.Id, orderid = x2.OrderId }).ToList();
+ }
+ private static void Demo3(SqlSugarClient db)
+ {
+ db.CodeFirst.InitTables();
+ db.Deleteable().ExecuteCommand();
+ db.Insertable(new operateinfo()
+ {
+ id=1,
+ operate_type=1,
+ operate_time=Convert.ToDateTime("2021-1-1")
+ }).ExecuteCommand();
+ db.Insertable(new operateinfo()
+ {
+ id = 1,
+ operate_type = 1,
+ operate_time = Convert.ToDateTime("2021-1-2")
+ }).ExecuteCommand();
+ db.Insertable(new operateinfo()
+ {
+ id = 1,
+ operate_type = 1,
+ operate_time = Convert.ToDateTime("2021-3-1")
+ }).ExecuteCommand();
+ db.Insertable(new operateinfo()
+ {
+ id = 1,
+ operate_type = 1,
+ operate_time = Convert.ToDateTime("2021-3-2")
+ }).ExecuteCommand();
+ db.Insertable(new operateinfo()
+ {
+ id = 1,
+ operate_type = 1,
+ operate_time = Convert.ToDateTime("2021-4-2")
+ }).ExecuteCommand();
+
+
+ var queryableLeft = db.Reportable(ReportableDateType.MonthsInLast1years).ToQueryable();
+ var queryableRight = db.Queryable();
+ var list= db.Queryable(queryableLeft, queryableRight, JoinType.Left,
+ (x1, x2) => x2.operate_time.ToString("yyyy-MM")==x1.ColumnName.ToString("yyyy-MM"))
+ .GroupBy((x1,x2)=>x1.ColumnName)
+ .Where(x1=>SqlFunc.Between(x1.ColumnName,DateTime.Now.AddYears(-1),DateTime.Now))
+ .Select((x1, x2) => new
+ {
+ count=SqlFunc.AggregateSum(SqlFunc.IIF(x2.id>0,1,0)) ,
+ date=x1.ColumnName.ToString("yyyy-MM")
+ }).ToList();
+ }
+
+
+ public partial class operateinfo
+ {
+ public operateinfo()
+ {
+
+
+ }
+ ///
+ /// Desc:操作序号
+ /// Default:
+ /// Nullable:False
+ ///
+ public int id { get; set; }
+
+ ///
+ /// Desc:操作时间
+ /// Default:
+ /// Nullable:False
+ ///
+ public DateTime operate_time { get; set; }
+
+ ///
+ /// Desc:操作类型
+ /// Default:
+ /// Nullable:False
+ ///
+ public int operate_type { get; set; }
+
+ ///
+ /// Desc:操作人编号
+ /// Default:
+ /// Nullable:False
+ ///
+ public int user_id { get; set; }
+
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Src/Asp.Net/QuestDbTest/Demo/Democ_GobalFilter.cs b/Src/Asp.Net/QuestDbTest/Demo/Democ_GobalFilter.cs
new file mode 100644
index 000000000..0bec17473
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Demo/Democ_GobalFilter.cs
@@ -0,0 +1,77 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest
+{
+ public class DemoC_GobalFilter
+ {
+ public static void Init()
+ {
+ Console.WriteLine("");
+ Console.WriteLine("#### Filter Start ####");
+ var db = GetInstance();
+
+
+ var sql = db.Queryable().ToSql();
+ //SELECT [Id],[Name],[Price],[CreateTime] FROM `order` WHERE isDelete=0
+ Console.WriteLine(sql);
+
+
+ var sql2 = db.Queryable((main,ot)=> main.Id==ot.OrderId).ToSql();
+ //SELECT [Id],[Name],[Price],[CreateTime] FROM `order` main ,[OrderDetail] ot WHERE ( [main].[Id] = [ot].[OrderId] ) AND main.isDelete=0
+ Console.WriteLine(sql2);
+
+
+ var sql3 = db.Queryable().Filter("Myfilter").ToSql();// Myfilter+Gobal
+ //SELECT [Id],[Name],[Price],[CreateTime] FROM `order` WHERE Name='jack' AND isDelete=0
+ Console.WriteLine(sql3);
+
+ var sql4 = db.Queryable().Filter("Myfilter",isDisabledGobalFilter:true).ToSql();//only Myfilter
+ //SELECT [Id],[Name],[Price],[CreateTime] FROM `order` WHERE Name='jack'
+ Console.WriteLine(sql4);
+ Console.WriteLine("#### Filter End ####");
+ }
+
+
+ public static SqlSugarClient GetInstance()
+ {
+ SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.QuestDB, ConnectionString = Config.ConnectionString, IsAutoCloseConnection = true });
+
+ //single table query gobal filter
+ db.QueryFilter.Add(new SqlFilterItem()
+ {
+ FilterValue = filterDb =>
+ {
+ //Writable logic
+ return new SqlFilterResult() { Sql = " isDelete=0" };//Global string perform best
+ }
+ });
+
+ //Multi-table query gobal filter
+ db.QueryFilter.Add(new SqlFilterItem()
+ {
+ FilterValue = filterDb =>
+ {
+ //Writable logic
+ return new SqlFilterResult() { Sql = " main.isDelete=0" };
+ },
+ IsJoinQuery=true
+ });
+
+ //Specific filters
+ db.QueryFilter.Add(new SqlFilterItem()
+ {
+ FilterName= "Myfilter",
+ FilterValue = filterDb =>
+ {
+ //Writable logic
+ return new SqlFilterResult() { Sql = "Name='jack'" };
+ }
+ });
+ return db;
+ }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/AttributeTable.cs b/Src/Asp.Net/QuestDbTest/Models/AttributeTable.cs
new file mode 100644
index 000000000..c1a43ad12
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/AttributeTable.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest
+{
+ [Table("MyAttributeTable")]
+ //[SugarTable("CustomAttributeTable")]
+ public class AttributeTable
+ {
+
+ [Key]
+ //[SugarColumn(IsPrimaryKey =true)]
+ public string Id { get; set; }
+ public string Name { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/CarType.cs b/Src/Asp.Net/QuestDbTest/Models/CarType.cs
new file mode 100644
index 000000000..00dc12710
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/CarType.cs
@@ -0,0 +1,7 @@
+namespace OrmTest
+{
+ public class CarType
+ {
+ public bool State { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Src/Asp.Net/QuestDbTest/Models/Custom.cs b/Src/Asp.Net/QuestDbTest/Models/Custom.cs
new file mode 100644
index 000000000..5e446d8ac
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/Custom.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ [SqlSugar.SugarTable("Custom_1")]
+ public class Custom
+ {
+ public long Id { get; set; }
+ public string Name { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/EntityMapper.cs b/Src/Asp.Net/QuestDbTest/Models/EntityMapper.cs
new file mode 100644
index 000000000..b597012fb
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/EntityMapper.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+namespace OrmTest
+{
+ [SugarTable("MyEntityMapper")]
+ public class EntityMapper
+ {
+ [SugarColumn(ColumnName ="MyName")]
+ public string Name { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/GJ_CN_2011_RtdEntity.cs b/Src/Asp.Net/QuestDbTest/Models/GJ_CN_2011_RtdEntity.cs
new file mode 100644
index 000000000..4c8f851e8
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/GJ_CN_2011_RtdEntity.cs
@@ -0,0 +1,205 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using SqlSugar;
+namespace OrmTest
+{
+
+ [SugarTable("GJ_CN_2011_Rtd")]//_{year}{month}{day}
+ [SugarIndex(null, nameof(MN), OrderByType.Asc)]
+ public class GJ_CN_2011_RtdEntity
+ {
+
+ ///
+ /// 记录ID
+ ///
+ [SugarColumn(IsPrimaryKey = true, ColumnDescription = "记录ID")]
+ public long Id { get; set; }
+
+ #region 数据拆包结果
+ ///
+ /// 数据段长度
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "数据段长度")]
+ public string DataLen { get; set; }
+ ///
+ /// 请求编号
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "请求编号")]
+ public string QN { get; set; }
+ ///
+ /// 系统编号
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "系统编号")]
+ public string ST { get; set; }
+ ///
+ /// 命令编号
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "命令编号")]
+ public string CN { get; set; }
+ ///
+ /// 访问密码
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "访问密码")]
+ public string PW { get; set; }
+ ///
+ /// 设备唯一标识
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "设备唯一标识", ColumnDataType = "symbol")]
+ public string MN { get; set; }
+ ///
+ /// 是否拆分包及应答标志
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "是否拆分包及应答标志")]
+ public string Flag { get; set; }
+
+ ///
+ /// 指令参数:数据包时间
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:数据包时间")]
+ public string CP_DataTime { get; set; }
+ ///
+ /// 指令参数:总悬浮颗粒物 TSP 空气质量 Mg/m3 N2.3标志位
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:总悬浮颗粒物 TSP 空气质量 Mg/m3 N2.3标志位")]
+ public string CP_a34001_Flag { get; set; }
+ ///
+ /// 指令参数:可吸入颗粒物PM10空气质量 ug/m3 N4.1标志位
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:可吸入颗粒物PM10空气质量 ug/m3 N4.1标志位")]
+ public string CP_a34002_Flag { get; set; }
+ ///
+ /// 指令参数:细微颗粒物 PM2.5 空气质量 ug/m3 N4.1标志位
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:细微颗粒物 PM2.5 空气质量 ug/m3 N4.1标志位")]
+ public string CP_a34004_Flag { get; set; }
+ ///
+ /// 指令参数:温度 空气质量 ℃ N3.1标志位
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:温度 空气质量 ℃ N3.1标志位")]
+ public string CP_a01001_Flag { get; set; }
+ ///
+ /// 指令参数:湿度 空气质量 %RH N3.2标志位
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:湿度 空气质量 %RH N3.2标志位")]
+ public string CP_a01002_Flag { get; set; }
+ ///
+ /// 指令参数:风速 空气质量 m/s N4.1标志位
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:风速 空气质量 m/s N4.1标志位")]
+ public string CP_a01007_Flag { get; set; }
+ ///
+ /// 指令参数:气压 空气质量 KPa N3.3标志位
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:气压 空气质量 KPa N3.3标志位")]
+ public string CP_a01006_Flag { get; set; }
+ ///
+ /// 指令参数:噪声瞬时声级标志位
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:噪声瞬时声级标志位")]
+ public string CP_LA_Flag { get; set; }
+ ///
+ /// 指令参数:风向 空气质量 [角]度 N4标志位
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:风向 空气质量 [角]度 N4标志位")]
+ public string CP_a01008_Flag { get; set; }
+ ///
+ /// CRC校验码
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "CRC校验码")]
+ public string CRC { get; set; }
+ #endregion
+
+ ///
+ /// 原始消息文本, ColumnDataType = "Nvarchar(MAX)"
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "原始消息文本")]
+ public string OriDatastring { get; set; }
+ ///
+ /// CRC计算结果
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "CRC计算结果")]
+ public string CRC_Calc { get; set; }
+ ///
+ /// CRC校验是否通过
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "CRC校验是否通过")]
+ public bool CRCVaild { get; set; }
+ ///
+ /// 数据拆包是否通过
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "数据拆包是否通过")]
+ public bool UnpackVaild { get; set; }
+ ///
+ /// 客户端IP地址
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "客户端IP地址")]
+ public string ClientIp { get; set; }
+ ///
+ /// 客户端端口号
+ ///
+ [SugarColumn(ColumnDescription = "客户端端口号")]
+ public int ClientPort { get; set; }
+ ///
+ /// 数据接收时间
+ ///
+ [SugarColumn(ColumnDescription = "数据接收时间")]
+
+ [TimeDbSplitField(DateType.Month)]
+ public DateTime RecTime { get; set; }
+ ///
+ /// 数据入库时间
+ ///
+ [SugarColumn(ColumnDescription = "数据接收时间")]
+ public DateTime CreateTime { get; set; } = DateTime.Now;
+
+
+
+
+ ///
+ /// 指令参数:总悬浮颗粒物 TSP 空气质量 Mg/m3 N2.3
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:总悬浮颗粒物 TSP 空气质量 Mg/m3 N2.3")]
+ public string CP_a34001_Rtd { get; set; }
+ ///
+ /// 指令参数:可吸入颗粒物PM10空气质量 ug/m3 N4.1
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:可吸入颗粒物PM10空气质量 ug/m3 N4.1")]
+ public string CP_a34002_Rtd { get; set; }
+ ///
+ /// 指令参数:细微颗粒物 PM2.5 空气质量 ug/m3 N4.1
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:细微颗粒物 PM2.5 空气质量 ug/m3 N4.1")]
+ public string CP_a34004_Rtd { get; set; }
+ ///
+ /// 指令参数:温度 空气质量 ℃ N3.1
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:温度 空气质量 ℃ N3.1")]
+ public string CP_a01001_Rtd { get; set; }
+ ///
+ /// 指令参数:湿度 空气质量 %RH N3.2
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:湿度 空气质量 %RH N3.2")]
+ public string CP_a01002_Rtd { get; set; }
+ ///
+ /// 指令参数:风速 空气质量 m/s N4.1
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:风速 空气质量 m/s N4.1")]
+ public string CP_a01007_Rtd { get; set; }
+ ///
+ /// 指令参数:气压 空气质量 KPa N3.3
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:气压 空气质量 KPa N3.3")]
+ public string CP_a01006_Rtd { get; set; }
+ ///
+ /// 指令参数:噪声瞬时声级
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:噪声瞬时声级")]
+ public string CP_LA_Rtd { get; set; }
+ ///
+ /// 指令参数:风向 空气质量 [角]度 N4
+ ///
+ [SugarColumn(IsNullable = true, ColumnDescription = "指令参数:风向 空气质量 [角]度 N4")]
+ public string CP_a01008_Rtd { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/Mapper.cs b/Src/Asp.Net/QuestDbTest/Models/Mapper.cs
new file mode 100644
index 000000000..8d7991d6c
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/Mapper.cs
@@ -0,0 +1,54 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ [SugarTable("OrderDetail")]
+ public class OrderItemInfo
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+ public int ItemId { get; set; }
+ public int OrderId { get; set; }
+ public decimal? Price { get; set; }
+ [SqlSugar.SugarColumn(IsNullable = true)]
+ public DateTime? CreateTime { get; set; }
+ [SugarColumn(IsIgnore = true)]
+ public Order Order { get; set; }
+ }
+ [SugarTable("Order")]
+ public class OrderInfo
+ {
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ [SugarColumn(IsIgnore = true)]
+ public List Items { get; set; }
+ }
+ public class ABMapping
+ {
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+ public int AId { get; set; }
+ public int BId { get; set; }
+ [SugarColumn(IsIgnore = true)]
+ public A A { get; set; }
+ [SugarColumn(IsIgnore = true)]
+ public B B { get; set; }
+
+ }
+ public class A
+ {
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ }
+ public class B
+ {
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/MyCustomAttributeTable.cs b/Src/Asp.Net/QuestDbTest/Models/MyCustomAttributeTable.cs
new file mode 100644
index 000000000..11359d062
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/MyCustomAttributeTable.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest
+{
+ [Table("CustomAttributeTable")]
+ //[SugarTable("CustomAttributeTable")]
+ public class MyCustomAttributeTable
+ {
+
+ [Key]
+ //[SugarColumn(IsPrimaryKey =true)]
+ public string Id { get; set; }
+ public string Name { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/Order.cs b/Src/Asp.Net/QuestDbTest/Models/Order.cs
new file mode 100644
index 000000000..ab2a6f134
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/Order.cs
@@ -0,0 +1,28 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest
+{
+ [SugarTable("order_1")]
+ public class Order
+ {
+ //不支持自增和主键 (标识主键是用来更新用的)
+ [SugarColumn(IsPrimaryKey = true)]
+ public long Id { get; set; }
+
+ public string Name { get; set; }
+ public decimal Price { get; set; }
+ // [SugarColumn(IsNullable = true,SqlParameterDbType =System.Data.DbType.Date)]
+ public DateTime CreateTime { get; set; }
+ [SugarColumn(IsNullable =true)]
+ public long CustomId { get; set; }
+
+ public double Value { get; set; }
+
+ [SugarColumn(IsIgnore = true)]
+ public List Items { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/OrderItem.cs b/Src/Asp.Net/QuestDbTest/Models/OrderItem.cs
new file mode 100644
index 000000000..bc921efb7
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/OrderItem.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OrmTest
+{
+ [SqlSugar.SugarTable("OrderDetail_1")]
+ public class OrderItem
+ {
+ //不支持自增和主键 (标识主键是用来更新用的)
+ [SqlSugar.SugarColumn(IsPrimaryKey =true)]
+ public long ItemId { get; set; }
+ public long OrderId { get; set; }
+ public decimal? Price { get; set; }
+ [SqlSugar.SugarColumn(IsNullable = true)]
+ public DateTime? CreateTime { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/SubInsertTest.cs b/Src/Asp.Net/QuestDbTest/Models/SubInsertTest.cs
new file mode 100644
index 000000000..42518befd
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/SubInsertTest.cs
@@ -0,0 +1,109 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class RootTable0
+ {
+ //不支持自增和主键 (标识主键是用来更新用的)
+ [SqlSugar.SugarColumn(IsPrimaryKey =true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ [SqlSugar.SugarColumn(IsIgnore =true)]
+ public TwoItem TwoItem { get; set; }
+ [SqlSugar.SugarColumn(IsIgnore = true)]
+ public TwoItem2 TwoItem2 { get; set; }
+ [SqlSugar.SugarColumn(IsIgnore = true)]
+ public List TwoItem3 { get; set; }
+ }
+ public class TwoItem
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
+ public int Id { get; set; }
+ public int RootId { get; set; }
+ public string Name { get; set; }
+ }
+ public class TwoItem2
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey = true)]
+ public string Id { get; set; }
+ public int RootId { get; set; }
+ [SqlSugar.SugarColumn(IsIgnore =true)]
+ public List ThreeItem2 { get; set; }
+ }
+ public class TwoItem3
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey = true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public string Desc { get; set; }
+ }
+ public class ThreeItem2
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey = true)]
+
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public string TwoItem2Id { get; set; }
+ }
+
+ public class Country
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey = true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+
+ [SqlSugar.SugarColumn(IsIgnore = true)]
+ public List Provinces { get; set; }
+ }
+
+ public class Province
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey =true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public int CountryId { get; set; }
+ [SqlSugar.SugarColumn(IsIgnore = true)]
+ public List citys { get; set; }
+ }
+
+ public class City
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey = true)]
+ public int Id { get; set; }
+ public int ProvinceId { get; set; }
+ public string Name { get; set; }
+ }
+
+
+ public class Country1
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+
+ [SqlSugar.SugarColumn(IsIgnore = true)]
+ public List Provinces { get; set; }
+ }
+
+ public class Province1
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public int CountryId { get; set; }
+ [SqlSugar.SugarColumn(IsIgnore = true)]
+ public List citys { get; set; }
+ }
+
+ public class City1
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey = true,IsIdentity =true)]
+ public int Id { get; set; }
+ public int ProvinceId { get; set; }
+ public string Name { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/TestTree.cs b/Src/Asp.Net/QuestDbTest/Models/TestTree.cs
new file mode 100644
index 000000000..b8250828a
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/TestTree.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class TestTree
+ {
+ [SqlSugar.SugarColumn(ColumnDataType = "hierarchyid")]
+ public string TreeId { get; set; }
+ [SqlSugar.SugarColumn(ColumnDataType = "Geography")]
+ public string GId { get; set; }
+ public string Name { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/Tree.cs b/Src/Asp.Net/QuestDbTest/Models/Tree.cs
new file mode 100644
index 000000000..d2878de64
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/Tree.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class Tree
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey =true)]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public int ParentId { get; set; }
+ [SqlSugar.SugarColumn(IsIgnore = true)]
+ public Tree Parent { get; set; }
+ [SqlSugar.SugarColumn(IsIgnore = true)]
+ public List Child { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/ViewOrder.cs b/Src/Asp.Net/QuestDbTest/Models/ViewOrder.cs
new file mode 100644
index 000000000..fcd465747
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/ViewOrder.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class ViewOrder:Order
+ {
+ public string CustomName { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Models/users.cs b/Src/Asp.Net/QuestDbTest/Models/users.cs
new file mode 100644
index 000000000..6b90a67d8
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Models/users.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+namespace OrmTest
+{
+ [SqlSugar.SugarTable("users")]
+ public class Users
+ {
+ [SugarColumn(IsPrimaryKey = true)]
+ public long Sid { get; set; }
+
+ public DateTime createtime { get; set; }
+ public string username { get; set; }
+
+ public string password { get; set; }
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Program.cs b/Src/Asp.Net/QuestDbTest/Program.cs
new file mode 100644
index 000000000..93b1d288b
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Program.cs
@@ -0,0 +1,38 @@
+using System;
+
+namespace OrmTest
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ //Demo
+ Demo0_SqlSugarClient.Init();
+ Demo1_Queryable.Init();
+ Demo2_Updateable.Init();
+ Demo3_Insertable.Init();
+ //DemoN_SplitTable.Init();
+ Demo4_Deleteable.Init();
+ Demo5_SqlQueryable.Init();
+ Demo6_Queue.Init();
+ Demo7_Ado.Init();
+ Demo8_Saveable.Init();
+ Demo9_EntityMain.Init();
+ DemoA_DbMain.Init();
+ DemoB_Aop.Init();
+ DemoC_GobalFilter.Init();
+ DemoD_DbFirst.Init();
+ DemoE_CodeFirst.Init();
+ DemoF_Utilities.Init();
+ DemoG_SimpleClient.Init();
+ //Unit test
+
+
+
+ Console.WriteLine("all successfully.");
+ Console.ReadKey();
+ }
+
+
+ }
+}
diff --git a/Src/Asp.Net/QuestDbTest/Properties/AssemblyInfo.cs b/Src/Asp.Net/QuestDbTest/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..6d38d60d8
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("QuestDbTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("QuestDbTest")]
+[assembly: AssemblyCopyright("Copyright © 2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("df49339d-3642-47ea-914a-5c7c6c066268")]
+
+// 程序集的版本信息由下列四个值组成:
+//
+// 主版本
+// 次版本
+// 生成号
+// 修订号
+//
+//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Src/Asp.Net/QuestDbTest/QuestDbTest.csproj b/Src/Asp.Net/QuestDbTest/QuestDbTest.csproj
new file mode 100644
index 000000000..76372e48c
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/QuestDbTest.csproj
@@ -0,0 +1,114 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {DF49339D-3642-47EA-914A-5C7C6C066268}
+ Exe
+ QuestDbTest
+ QuestDbTest
+ v4.6
+ 512
+ true
+ true
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ False
+ ..\SqlSugar\References\Npgsql.dll
+
+
+
+ ..\packages\System.Buffers.4.4.0\lib\netstandard1.1\System.Buffers.dll
+
+
+
+
+ ..\packages\System.Memory.4.5.2\lib\netstandard1.1\System.Memory.dll
+
+
+ ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll
+
+
+ ..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll
+
+
+ ..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {489bb790-226c-4fad-8d1e-51d72a7ff8e5}
+ SqlSugar
+
+
+
+
\ No newline at end of file
diff --git a/Src/Asp.Net/QuestDbTest/packages.config b/Src/Asp.Net/QuestDbTest/packages.config
new file mode 100644
index 000000000..961262bf1
--- /dev/null
+++ b/Src/Asp.Net/QuestDbTest/packages.config
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Src/Asp.Net/SqlSugar.sln b/Src/Asp.Net/SqlSugar.sln
index 7b50a17b7..f732d61b7 100644
--- a/Src/Asp.Net/SqlSugar.sln
+++ b/Src/Asp.Net/SqlSugar.sln
@@ -43,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomDbTest", "CustomDbTes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Json2SqlTest", "Json2SqlTest\Json2SqlTest.csproj", "{B30F8D3F-7A48-4C7B-B808-A3F900B9F3D4}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuestDbTest", "QuestDbTest\QuestDbTest.csproj", "{DF49339D-3642-47EA-914A-5C7C6C066268}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -121,6 +123,10 @@ Global
{B30F8D3F-7A48-4C7B-B808-A3F900B9F3D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B30F8D3F-7A48-4C7B-B808-A3F900B9F3D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B30F8D3F-7A48-4C7B-B808-A3F900B9F3D4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DF49339D-3642-47EA-914A-5C7C6C066268}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DF49339D-3642-47EA-914A-5C7C6C066268}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DF49339D-3642-47EA-914A-5C7C6C066268}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DF49339D-3642-47EA-914A-5C7C6C066268}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs
index 32a1d4c15..b6c887515 100644
--- a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs
+++ b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs
@@ -408,7 +408,7 @@ namespace SqlSugar
Check.Exception(InstanceFactory.CustomDllName.IsNullOrEmpty(), "DbType.Custom: InstanceFactory.CustomDllName is not null ");
break;
case DbType.QuestDB:
- Check.Exception(SugarCompatible.IsFramework, "QuestDB only support .net core");
+ DependencyManagement.TryPostgreSQL();
break;
case DbType.ClickHouse:
Check.Exception(SugarCompatible.IsFramework, "ClickHouse only support .net core");
diff --git a/Src/Asp.Net/SqlSugar/Realization/QuestDB/CodeFirst/QuestDBCodeFirst.cs b/Src/Asp.Net/SqlSugar/Realization/QuestDB/CodeFirst/QuestDBCodeFirst.cs
new file mode 100644
index 000000000..cdc51e432
--- /dev/null
+++ b/Src/Asp.Net/SqlSugar/Realization/QuestDB/CodeFirst/QuestDBCodeFirst.cs
@@ -0,0 +1,101 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+
+namespace SqlSugar
+{
+ public class QuestDBCodeFirst : CodeFirstProvider
+ {
+ protected override void ExistLogicEnd(List dbColumns)
+ {
+ foreach (EntityColumnInfo column in dbColumns)
+ {
+ if (column.DefaultValue != null)
+ {
+ this.Context.DbMaintenance.AddDefaultValue(column.DbTableName,column.DbColumnName,column.DefaultValue.ToSqlValue());
+ }
+ }
+ }
+ public override void NoExistLogic(EntityInfo entityInfo)
+ {
+ var tableName = GetTableName(entityInfo);
+ //Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");
+ List columns = new List();
+ if (entityInfo.Columns.HasValue())
+ {
+ foreach (var item in entityInfo.Columns.Where(it=>it.IsIgnore==false))
+ {
+ DbColumnInfo dbColumnInfo = this.EntityColumnToDbColumn(entityInfo, tableName, item);
+ columns.Add(dbColumnInfo);
+ }
+ if (entityInfo.IsCreateTableFiledSort)
+ {
+ columns = columns.OrderBy(c => c.CreateTableFieldSort).ToList();
+ }
+ }
+ columns = columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).ToList();
+ foreach (var propety in entityInfo.Type.GetProperties())
+ {
+ var timeAttr= propety.GetCustomAttribute();
+ if (timeAttr != null)
+ {
+ var colName = columns.FirstOrDefault(it => it.PropertyName == propety.Name)?.DbColumnName;
+ tableName +=$"_TIMESTAMP({colName}) PARTITION BY {timeAttr.DateType} ";
+ }
+ }
+ this.Context.DbMaintenance.CreateTable(tableName, columns,true);
+ }
+ protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
+ {
+ var propertyType = UtilMethods.GetUnderType(item.PropertyInfo);
+ var result = new DbColumnInfo()
+ {
+ TableId = entityInfo.Columns.IndexOf(item),
+ DbColumnName = item.DbColumnName.HasValue() ? item.DbColumnName : item.PropertyName,
+ IsPrimarykey = item.IsPrimarykey,
+ IsIdentity = item.IsIdentity,
+ TableName = tableName,
+ IsNullable = item.IsNullable,
+ DefaultValue = item.DefaultValue,
+ ColumnDescription = item.ColumnDescription,
+ PropertyName=item.PropertyName,
+ Length = item.Length,
+ CreateTableFieldSort = item.CreateTableFieldSort
+ };
+ if (propertyType == UtilConstants.DecType)
+ {
+ result.Scale = item.DecimalDigits;
+ result.DecimalDigits = item.DecimalDigits;
+ }
+ GetDbType(item, propertyType, result);
+ if (result.DataType.Equals("varchar", StringComparison.CurrentCultureIgnoreCase) && result.Length == 0)
+ {
+ result.Length = 1;
+ }
+ return result;
+ }
+
+ protected override void ConvertColumns(List dbColumns)
+ {
+ foreach (var item in dbColumns)
+ {
+ if (item.DataType == "DateTime")
+ {
+ item.Length = 0;
+ }
+ }
+ }
+
+ protected override void ChangeKey(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
+ {
+ this.Context.DbMaintenance.UpdateColumn(tableName, EntityColumnToDbColumn(entityInfo, tableName, item));
+ if (!item.IsPrimarykey)
+ this.Context.DbMaintenance.DropConstraint(tableName,null);
+ if (item.IsPrimarykey)
+ this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName);
+ }
+
+ }
+}
diff --git a/Src/Asp.Net/SqlSugar/Realization/QuestDB/DbBind/QuestDBDbBind.cs b/Src/Asp.Net/SqlSugar/Realization/QuestDB/DbBind/QuestDBDbBind.cs
new file mode 100644
index 000000000..8847e3d57
--- /dev/null
+++ b/Src/Asp.Net/SqlSugar/Realization/QuestDB/DbBind/QuestDBDbBind.cs
@@ -0,0 +1,133 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace SqlSugar
+{
+ public class QuestDBDbBind : DbBindProvider
+ {
+ public override string GetPropertyTypeName(string dbTypeName)
+ {
+ dbTypeName = dbTypeName.ToLower();
+ var propertyTypes = MappingTypes.Where(it => it.Value.ToString().ToLower() == dbTypeName || it.Key.ToLower() == dbTypeName);
+ if (propertyTypes == null)
+ {
+ return "other";
+ }
+ else if (dbTypeName == "xml" || dbTypeName == "string"|| dbTypeName == "jsonb"|| dbTypeName == "json")
+ {
+ return "string";
+ }else if (dbTypeName == "bpchar")//数据库char datatype 查询出来的时候是 bpchar
+ {
+ return "char";
+ }
+ if (dbTypeName == "byte[]")
+ {
+ return "byte[]";
+ }
+ else if (propertyTypes == null || propertyTypes.Count() == 0)
+ {
+ if (dbTypeName.StartsWith("_"))
+ {
+ var dbTypeName2 = dbTypeName.TrimStart('_');
+ return MappingTypes.Where(it => it.Value.ToString().ToLower() == dbTypeName2 || it.Key.ToLower() == dbTypeName2).Select(it => it.Value + "[]").First();
+ }
+ Check.ThrowNotSupportedException(string.Format(" \"{0}\" Type NotSupported, DbBindProvider.GetPropertyTypeName error.", dbTypeName));
+ return null;
+ }
+ else if (propertyTypes.First().Value == CSharpDataType.byteArray)
+ {
+ return "byte[]";
+ }
+ else
+ {
+ return propertyTypes.First().Value.ToString();
+ }
+ }
+ public override List> MappingTypes
+ {
+ get
+ {
+ var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
+ if (extService != null && extService.AppendDataReaderTypeMappings.HasValue())
+ {
+ return extService.AppendDataReaderTypeMappings.Union(MappingTypesConst).ToList();
+ }
+ else
+ {
+ return MappingTypesConst;
+ }
+ }
+ }
+ public static List> MappingTypesConst = new List>(){
+
+ new KeyValuePair("byte",CSharpDataType.@byte),
+ new KeyValuePair("short",CSharpDataType.@short),
+ new KeyValuePair("smallint",CSharpDataType.@short),
+ new KeyValuePair("int",CSharpDataType.@int),
+ new KeyValuePair("integer",CSharpDataType.@int),
+ new KeyValuePair("long",CSharpDataType.@long),
+ new KeyValuePair("bigint",CSharpDataType.@long),
+ new KeyValuePair("long256",CSharpDataType.@long),
+ new KeyValuePair("float",CSharpDataType.@float),
+ new KeyValuePair("real",CSharpDataType.@float),
+ new KeyValuePair("double",CSharpDataType.@double),
+ new KeyValuePair("double precision",CSharpDataType.@int),
+ new KeyValuePair("double",CSharpDataType.@decimal),
+ new KeyValuePair("decimal",CSharpDataType.@decimal),
+ new KeyValuePair("path",CSharpDataType.@decimal),
+ new KeyValuePair("point",CSharpDataType.@decimal),
+ new KeyValuePair("polygon",CSharpDataType.@decimal),
+
+ //new KeyValuePair("int",CSharpDataType.@bool),
+ new KeyValuePair("boolean",CSharpDataType.@bool),
+ new KeyValuePair("bool",CSharpDataType.@bool),
+ new KeyValuePair("box",CSharpDataType.@bool),
+ new KeyValuePair("bytea",CSharpDataType.@bool),
+
+ new KeyValuePair("string",CSharpDataType.@string),
+ new KeyValuePair("character varying",CSharpDataType.@string),
+ new KeyValuePair("geometry",CSharpDataType.@string),
+ new KeyValuePair("name",CSharpDataType.@string),
+ new KeyValuePair("text",CSharpDataType.@string),
+ new KeyValuePair("symbol",CSharpDataType.@string),
+ new KeyValuePair("char",CSharpDataType.@string),
+ new KeyValuePair("character",CSharpDataType.@string),
+ new KeyValuePair("cidr",CSharpDataType.@string),
+ new KeyValuePair("circle",CSharpDataType.@string),
+ new KeyValuePair("tsquery",CSharpDataType.@string),
+ new KeyValuePair("tsvector",CSharpDataType.@string),
+ new KeyValuePair("txid_snapshot",CSharpDataType.@string),
+ new KeyValuePair("string",CSharpDataType.Guid),
+ new KeyValuePair("xml",CSharpDataType.@string),
+ new KeyValuePair("json",CSharpDataType.@string),
+
+ new KeyValuePair("interval",CSharpDataType.@decimal),
+ new KeyValuePair("lseg",CSharpDataType.@decimal),
+ new KeyValuePair("macaddr",CSharpDataType.@decimal),
+ new KeyValuePair("money",CSharpDataType.@decimal),
+ new KeyValuePair("timestamp",CSharpDataType.DateTime),
+ new KeyValuePair("timestamptz",CSharpDataType.DateTime),
+ new KeyValuePair("timestamp without time zone",CSharpDataType.DateTime),
+ new KeyValuePair("date",CSharpDataType.DateTime),
+ new KeyValuePair("time",CSharpDataType.DateTime),
+ new KeyValuePair("time with time zone",CSharpDataType.DateTime),
+ new KeyValuePair("timetz",CSharpDataType.DateTime),
+ new KeyValuePair("time without time zone",CSharpDataType.DateTime),
+
+ new KeyValuePair("binary",CSharpDataType.byteArray),
+ new KeyValuePair