在上⼀个操作完成之前,在此上下⽂上启动了第⼆个操作。这通
常是由使⽤同⼀dbcontext实。。。
“A second operation started on this context before a previous operation completed. This is usually caused by different threads using thesame instance of DbContext, however instance members are not g
在上⼀个操作完成之前,在此上下⽂上启动了第⼆个操作。这通常是由使⽤同⼀dbcontext实例的不同线程造成的,但是实例成员不能保证线程安全。这也可能是由于在客户端上计算的嵌套查询造成的,如果是这种情况,请重写查询以避免嵌套调⽤。如果DbContext使⽤的是IoC和依赖注⼊那么只需要将
services.AddDbContext(options => options.UseSqlServer(connection));这段代码修改为
services.AddDbContext(options => options.UseSqlServer(connection), ServiceLifetime.Transient);ServiceLifetime.Transient:指定每次请求服务时都将创建该服务的新实例