一条普通的查询偶发Collection was modified;错误 返回
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at SqlSugar.SqlSugarProvider.InitMappingInfo(EntityInfo entityInfo)
at SqlSugar.SqlSugarProvider.InitMappingInfo(Type type)
at SqlSugar.SqlSugarProvider.InitMappingInfo[T]()
at SqlSugar.SqlSugarProvider.Queryable[T]()
at SqlSugar.SqlSugarClient.Queryable[T]()
业务代码如下:
int result = SqlSugarUtil.GetSqlSugarClient()
.Queryable<CommunityDoctorDto>()
.Where(t => t.Code == doctorCode)
.Count();
return result > 0;
数据库配置如下:
if (instance == null)
{
instance = new SqlSugarClient(
new ConnectionConfig()
{
ConnectionString = DBConnectionString,
DbType = SqlSugar.DbType.MySql, // 设置数据库类型
IsAutoCloseConnection = true, // 自动释放数据务,如果存在事务,在事务结束后释放.
InitKeyType = InitKeyType.Attribute // 从实体特性中读取主键自增列信息
});
instance.Ado.CommandTimeOut = 30000; // 设置超时时间
instance.Aop.OnLogExecuted = (sql, pars) => { };
// SQL执行完事件
instance.Aop.OnLogExecuting = (sql, pars) =>
{
//Console.WriteLine(sql);
}; // SQL执行前事件
// 执行SQL错误事件
instance.Aop.OnError = (ex) => throw new Exception(ex.Message);
// SQL执行前可以修改SQL
instance.Aop.OnExecutingChangeSql = (sql, pars) => new KeyValuePair<string, SugarParameter[]>(sql, pars);
}
热忱回答(2)
-
fate stay night VIP0
2020/6/12ORM不能用单例
0 回复 -
madfrog VIP0
2020/6/15@fate stay night:您好,谢谢你了,我按照你说的试试。
0 回复