mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
测试ClickHouse Bool映射插入
This commit is contained in:
parent
dc73a1571a
commit
3528c01c5b
@ -8,11 +8,14 @@ using System.Diagnostics;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using FreeSql.DataAnnotations;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace FreeSql.Tests.ClickHouse
|
||||
{
|
||||
public class ClickHouseTest2
|
||||
{
|
||||
|
||||
|
||||
private static IFreeSql fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse,
|
||||
"Host=127.0.0.1;Port=8123;Database=test;Compress=True;Min Pool Size=1")
|
||||
.UseMonitorCommand(cmd => Console.WriteLine($"线程:{cmd.CommandText}\r\n"))
|
||||
@ -29,6 +32,7 @@ namespace FreeSql.Tests.ClickHouse
|
||||
{
|
||||
fsql.CodeFirst.SyncStructure(typeof(PositionInfoModel));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Issuse1587TestOnePrimary()
|
||||
{
|
||||
|
87
FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest3.cs
Normal file
87
FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest3.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FreeSql.DataAnnotations;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace FreeSql.Tests.ClickHouse
|
||||
{
|
||||
public class ClickHouseTest3
|
||||
{
|
||||
private static ITestOutputHelper _output;
|
||||
private static IFreeSql _fsql;
|
||||
|
||||
public ClickHouseTest3(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
_fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse,
|
||||
"Host=192.168.1.123;Port=8123;Database=test;Compress=True;Min Pool Size=1")
|
||||
.UseMonitorCommand(cmd => _output.WriteLine($"线程:{cmd.CommandText}\r\n"))
|
||||
.UseNoneCommandParameter(false)
|
||||
.Build();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试bool类型映射
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestBoolMappingSync()
|
||||
{
|
||||
_fsql.CodeFirst.SyncStructure(typeof(BoolMappingTest));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试bool类型映射
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestBoolMappingInsert()
|
||||
{
|
||||
_fsql.Insert(new BoolMappingTest
|
||||
{
|
||||
Name = "Tom",
|
||||
Age = 20,
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
IsDelete = true,
|
||||
IsEnable = true
|
||||
}).ExecuteAffrows();
|
||||
|
||||
_fsql.Insert(new BoolMappingTest
|
||||
{
|
||||
Name = "Jess",
|
||||
Age = 21,
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
IsDelete = true,
|
||||
IsEnable = false
|
||||
}).ExecuteAffrows();
|
||||
|
||||
_fsql.Insert(new BoolMappingTest
|
||||
{
|
||||
Name = "Daily",
|
||||
Age = 22,
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
IsDelete = true,
|
||||
IsEnable = null
|
||||
}).ExecuteAffrows();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Table(Name = "table_test_bool")]
|
||||
public class BoolMappingTest
|
||||
{
|
||||
[Column(IsPrimary = true, Name = "id")]
|
||||
public string Id { set; get; }
|
||||
|
||||
[Column(Name = "name")] public string Name { get; set; }
|
||||
|
||||
[Column(Name = "age")] public int Age { get; set; }
|
||||
|
||||
[Column(Name = "is_delete")] public bool IsDelete { get; set; }
|
||||
|
||||
[Column(Name = "is_enable")] public bool? IsEnable { get; set; }
|
||||
}
|
||||
}
|
@ -43,8 +43,9 @@ namespace FreeSql.ClickHouse
|
||||
if (col.DbScale != 0) ret.Scale = col.DbScale;
|
||||
break;
|
||||
}
|
||||
if (value is bool)
|
||||
ret.Value = (bool)value ? 1 : 0;
|
||||
//直接使用Bool
|
||||
//if (value is bool)
|
||||
// ret.Value = (bool)value ? 1 : 0;
|
||||
}
|
||||
_params?.Add(ret);
|
||||
return ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user