Browse Source

Update clickhouse

SqlSugar5
sunkaixuan 2 years ago
parent
commit
f72dbb7a14
  1. 35
      Src/Asp.NetCore2/ClickHouseTest/Demo/DemoE_CodeFirst.cs
  2. 10
      Src/Asp.NetCore2/SqlSugar.ClickHouseCore/ClickHouse/ClickHouseProvider.cs

35
Src/Asp.NetCore2/ClickHouseTest/Demo/DemoE_CodeFirst.cs

@ -23,10 +23,43 @@ namespace OrmTest
db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1 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<CodeFirstTable1>().ToList(); var list = db.Queryable<CodeFirstTable1>().ToList();
TestBool(db);
TestGuid(db);
Console.WriteLine("#### CodeFirst end ####"); Console.WriteLine("#### CodeFirst end ####");
} }
private static void TestGuid(SqlSugarClient db)
{
db.CodeFirst.InitTables<GuidTest>();
db.DbMaintenance.TruncateTable("BoolTest");
var Id = 1;
db.Insertable<GuidTest>(new GuidTest() { A = Guid.Empty, Id = Id }).ExecuteCommand();
Console.Write(db.Queryable<GuidTest>().First().A);
db.Updateable<GuidTest>(new GuidTest() { A = Guid.NewGuid(), Id = Id }).ExecuteCommand();
Console.Write(db.Queryable<GuidTest>().First().A);
}
private static void TestBool(SqlSugarClient db)
{
db.CodeFirst.InitTables<BoolTest>();
db.DbMaintenance.TruncateTable("BoolTest");
var Id = 1;
db.Insertable<BoolTest>(new BoolTest() { A = true, Id = Id }).ExecuteCommand();
Console.Write(db.Queryable<BoolTest>().First().A);
db.Updateable<BoolTest>(new BoolTest() { A = false, Id = Id }).ExecuteCommand();
Console.Write(db.Queryable<BoolTest>().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 public class CodeFirstTable1
{ {
[SugarColumn(IsPrimaryKey = true)] [SugarColumn(IsPrimaryKey = true)]

10
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; 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&&param.Value!=DBNull.Value&&dbtype.ObjToString() == System.Data.DbType.Boolean.ToString())
{ {
sql = sql.Replace(param.ParameterName, param.Value.ObjToBool()?"1":"0"); 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 else
{ {
sql = sql.Replace(param.ParameterName, "{" + newName + ":" + dbtype + "}"); sql = sql.Replace(param.ParameterName, "{" + newName + ":" + dbtype + "}");

Loading…
Cancel
Save