Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET Core 3.1 API给出错误:在上一个操作完成之前,在此上下文上启动了第二个操作_C#_Asp.net_Entity Framework Core - Fatal编程技术网

C# .NET Core 3.1 API给出错误:在上一个操作完成之前,在此上下文上启动了第二个操作

C# .NET Core 3.1 API给出错误:在上一个操作完成之前,在此上下文上启动了第二个操作,c#,asp.net,entity-framework-core,C#,Asp.net,Entity Framework Core,我有一个核心的3.1 API,它与postgres DB一起工作。所有的方法和控制器都是异步的,所有的方法调用都有wait。我发出的请求都是GET,并且不会更改db。但有时我会犯这样的错误: 在上一个操作完成之前,在此上下文上启动了第二个操作。这通常是由使用同一DbContext实例的不同线程引起的 我在服务中所做的,控制器正在调用的是: 等待此.repository.All().SingleOrDefaultAsync(x=>x.code==code&&x.ValidTo>this.dateT

我有一个核心的3.1 API,它与postgres DB一起工作。所有的方法和控制器都是异步的,所有的方法调用都有wait。我发出的请求都是GET,并且不会更改db。但有时我会犯这样的错误:

在上一个操作完成之前,在此上下文上启动了第二个操作。这通常是由使用同一DbContext实例的不同线程引起的

我在服务中所做的,控制器正在调用的是:

等待此.repository.All().SingleOrDefaultAsync(x=>x.code==code&&x.ValidTo>this.dateTimeProvider.GetDateTimeUtcNow());
然后是if-else的逻辑,就这样。 DbContext由“AddDbContextPool”添加。 上下文和存储库都在InstancePerLifetimeScope中注册


我应该指出,如果我得到这个错误,我会向那个API发出两个get请求。但问题并非持续存在。

可能您在某个电话中错过了
wait
。需要手动检查。