FreeSql
FreeSql copied to clipboard
IBaseRepository.UpdateAsync()方法批量更新概率性报错
问题描述及重现代码:
- 该方法为定时任务调度,一个小时执行一次。 应该不存在多线程问题。
- 执行逻辑是循环每次获取100条数据,修改数据之后调用UpdateAsync()方法批量更新
- 报错为概率性,不是必现,但是概率较大。
- 报错信息如下:
ArgumentOutOfRangeException: Index must be within the bounds of the List. (Parameter 'index')
at System.Collections.Generic.List
1.InsertRange(System.Int32 index, System.Collections.Generic.IEnumerable
1 collection) at offset 268 at FreeSql.DbSet`1.<DbContextBatchUpdatePrivAsync>d__65.MoveNext() at offset 944 at FreeSql.<>c__DisplayClass62_0.<<FlushCommandAsync>g__funcUpdate|3>d.MoveNext() at offset 269 at FreeSql.DbContext.<FlushCommandAsync>d__62.MoveNext() at offset 1337 at FreeSql.RepositoryDbContext.<SaveChangesAsync>d__8.MoveNext() at offset 111
while(true)
{
var list = _repository.where(...).take(100).ToListAsync();
......
await _repository.UpdateAsync(list);
await Task.Delay(100);
}
数据库版本
Mysql 8.0
安装的Nuget包
3.2.8
.net framework/. net core? 及具体版本
.net 6.0
控制不要多线程访问 _repository 这个对象