IntoTable使用SplitTable插入数据失败 返回
SqlSugar
沟通中
7
337
发布于2024/2/5
悬赏:0 飞吻
使用下面这种写法会报错
await this.db.Queryable<WESStockTertiary>().Select(i => new StockSnapshotTertiary { SnapshotTime = time }, true).SplitTable().IntoTableAsync<StockSnapshotTertiary>();
异常为
MySqlConnector.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) SELECT * FROM ( ( SELECT timestamp('2024-02-05 20:00:00.000000') AS `Snapsho' at line 1 at SqlSugar.MySqlProvider.ExecuteCommandAsync(String sql, SugarParameter[] parameters) at SqlSugar.MySqlProvider.ExecuteCommandAsync(String sql, SugarParameter[] parameters) at SqlSugar.QueryableProvider`1.IntoTableAsync(Type TableEntityType, String TableName, CancellationToken cancellationToken) at WES.Repository.Repository.StockRepository.GenerateStockSnapshotAsync() in D:\code\WES\WES.Repository\Repository\StockRepository.cs:line 900 at WES.Builder.StockSnapshotBackgroundService.DoWorkAsync(CancellationToken stoppingToken) in D:\code\WES\WES.Builder\StockSnapshotBackgroundService.cs:line 36 at WES.Builder.StockSnapshotBackgroundService.ExecuteAsync(CancellationToken stoppingToken) in D:\code\WES\WES.Builder\StockSnapshotBackgroundService.cs:line 27 at Microsoft.Extensions.Hosting.Internal.Host.TryExecuteBackgroundServiceAsync(BackgroundService backgroundService)
但如果我我不使用分表,使用下面的这种写法就能插入
var tableName = $"wes_stock_tertiary_{time.Year}0101"; await this.db.Queryable<WESStockTertiary>().Select(i => new StockSnapshotTertiary { SnapshotTime = time }, true).IntoTableAsync<StockSnapshotTertiary>(tableName);
热忱回答(7)
-
fate sta VIP02024/2/5
这个目前不支持分表
推荐用
queryable.As(表名)
0 回复 -
VIP02024/2/5
不是很明白,能给个大概的样子吗
0 回复 -
fate sta VIP02024/2/5
this
.db.Queryable<WESStockTertiary>().AS(表名)
.Select(i =>new
StockSnapshotTertiary
{
SnapshotTime = time
},
true
).IntoTableAsync<StockSnapshotTertiary>(tableName);
0 回复 -
fate sta VIP02024/2/5
自动分表有获取所有分表名的方法
0 回复 -
fate sta VIP02024/2/5
循环一下 所有分表就行了
0 回复 -
fate sta VIP02024/2/5
//用例1:获取所有表表名 ,可以用于循环处理每个表
var
tables=db.SplitHelper<Order>().GetTables();
0 回复 -
fate sta VIP02024/2/5
循环后AS(表名)
0 回复