dotnetcore / FreeSql

🦄 .NET aot orm, C# orm, VB.NET orm, Mysql orm, Postgresql orm, SqlServer orm, Oracle orm, Sqlite orm, Firebird orm, 达梦 orm, 人大金仓 orm, 神通 orm, 翰高 orm, 南大通用 orm, 虚谷 orm, 国产 orm, Clickhouse orm, DuckDB orm, TDengine orm, QuestDB orm, MsAccess orm.
https://dotnetcore.github.io/FreeSql/
MIT License
4.11k stars 857 forks source link

QuestDb ExecuteQuestDbBulkCopy 有时插入无效 #1842

Closed yangbocheng closed 1 month ago

yangbocheng commented 4 months ago

问题描述及重现代码:

如按下方 var ef1 = await fsql.Insert<Books2>().AppendData(list).ExecuteAffrowsAsync(); 插入时有效,数据行增加 image

而按fsql.Insert(list).ExecuteQuestDbBulkCopy();插入时,不报错,但是插入后表中实际未增加数据 image

public class Books2
{
    public string Name { get; set; }
    public string Sex { get; set; }

    [AutoSubtable(SubtableType.Day)]
    public DateTime? tim1 { get; set; }
}
var fsql = new FreeSqlBuilder()
    .UseConnectionString(DataType.QuestDb, "host=localhost;port=8812;username=admin;password=quest;database=qdb;ServerCompatibilityMode=NoTypeLoading;")
    .UseMonitorCommand(cmd => Debug.WriteLine($"Sql:{cmd.CommandText}")) //监听SQL语句
    .UseAutoSyncStructure(true)
    .UseQuestDbRestAPI("localhost:9000")
    .Build();

var one = new Books
{
    Name = "Adsasd1",
    Sex = "sexsad2"
};
var time1 = DateTime.Now;
List<Books2> list = new List<Books2>();

//var q1 = fsql.CodeFirst.GetComparisonDDLStatements(typeof(Books2));

for (int i = 0; i < 10_000_000; i++)
{
    list.Add(new Books2
    {
        Name = $"name{i}",
        Sex = $"sex_{i}",
        tim1 = time1.AddMinutes(i).AddSeconds(Random.Shared.Next(0, 59))
    });

    if ((i > 0 && i % 10 == 0) || (i + 1 == 10_000_000))
    {
        var ef1 = await fsql.Insert<Books2>().AppendData(list).ExecuteAffrowsAsync();
        //var ef1 = fsql.Insert(list).ExecuteQuestDbBulkCopy();
        list = new List<Books2>();
        Console.WriteLine($"inserted {ef1} ef");

    }

}

Console.ReadLine();

数据库版本

QuestDb : questdb-8.0.1-rt-windows-amd64

安装的Nuget包

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FreeSql.Provider.QuestDb" Version="3.2.833-preview20260627" />
    <PackageReference Include="net-questdb-client" Version="2.0.0" />
  </ItemGroup>

</Project>

.net framework/. net core? 及具体版本

net8.0

2881099 commented 4 months ago

AutoSubtable 是不是个这个有关,建议debug一下源码。

d4ilys commented 4 months ago

QuestDb在分表时BulkCopy,要加上Id作为唯一标识

public class Books2
{
    public string Id {get;set;}
    public string Name { get; set; }
    public string Sex { get; set; }

    [AutoSubtable(SubtableType.Day)]
    public DateTime? tim1 { get; set; }
}