From f72dbb7a146f481f2e73426f49b89cbf9ba19557 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 14 Aug 2022 03:18:19 +0800 Subject: [PATCH] Update clickhouse --- .../ClickHouseTest/Demo/DemoE_CodeFirst.cs | 37 ++++++++++++++++++- .../ClickHouse/ClickHouseProvider.cs | 10 ++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Src/Asp.NetCore2/ClickHouseTest/Demo/DemoE_CodeFirst.cs b/Src/Asp.NetCore2/ClickHouseTest/Demo/DemoE_CodeFirst.cs index 43f965478..35315ed34 100644 --- a/Src/Asp.NetCore2/ClickHouseTest/Demo/DemoE_CodeFirst.cs +++ b/Src/Asp.NetCore2/ClickHouseTest/Demo/DemoE_CodeFirst.cs @@ -21,12 +21,45 @@ namespace OrmTest }); //db.DbMaintenance.CreateDatabase(); db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1 - db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand(); + db.Insertable(new CodeFirstTable1() { Name = "a", Text = "a" }).ExecuteCommand(); var list = db.Queryable().ToList(); + TestBool(db); + TestGuid(db); Console.WriteLine("#### CodeFirst end ####"); } + private static void TestGuid(SqlSugarClient db) + { + db.CodeFirst.InitTables(); + db.DbMaintenance.TruncateTable("BoolTest"); + var Id = 1; + 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("BoolTest"); + var Id = 1; + db.Insertable(new BoolTest() { A = true, Id = Id }).ExecuteCommand(); + Console.Write(db.Queryable().First().A); + db.Updateable(new BoolTest() { A = false, Id = Id }).ExecuteCommand(); + Console.Write(db.Queryable().First().A); + } + } + public class GuidTest + { + [SugarColumn(IsPrimaryKey = true)] + public long Id { get; set; } + public Guid A { get; set; } + } + public class BoolTest + { + [SugarColumn(IsPrimaryKey =true)] + public long Id { get; set; } + public bool A { get; set; } } - public class CodeFirstTable1 { [SugarColumn(IsPrimaryKey = true)] diff --git a/Src/Asp.NetCore2/SqlSugar.ClickHouseCore/ClickHouse/ClickHouseProvider.cs b/Src/Asp.NetCore2/SqlSugar.ClickHouseCore/ClickHouse/ClickHouseProvider.cs index c4e355f77..91ee3e8db 100644 --- a/Src/Asp.NetCore2/SqlSugar.ClickHouseCore/ClickHouse/ClickHouseProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar.ClickHouseCore/ClickHouse/ClickHouseProvider.cs @@ -125,10 +125,18 @@ namespace SqlSugar.ClickHouse { dbtype = ClickHouseDbBind.MappingTypesConst.First(it => it.Value == CSharpDataType.@decimal).Key; } - if (dbtype.ObjToString() == System.Data.DbType.Boolean.ToString()) + if (dbtype.ObjToString() == System.Data.DbType.Guid.ToString()) + { + dbtype = ClickHouseDbBind.MappingTypesConst.First(it => it.Value == CSharpDataType.Guid).Key; + } + if (param.Value!=null&¶m.Value!=DBNull.Value&&dbtype.ObjToString() == System.Data.DbType.Boolean.ToString()) { sql = sql.Replace(param.ParameterName, param.Value.ObjToBool()?"1":"0"); } + else if (dbtype.ObjToString() == System.Data.DbType.Boolean.ToString()) + { + sql = sql.Replace(param.ParameterName, "null"); + } else { sql = sql.Replace(param.ParameterName, "{" + newName + ":" + dbtype + "}");