SCF
SCF copied to clipboard
dbcontext 并发异常该如何处理 我直接那demo 页面请求改成 api 用jmeter 并发测试出现以下异常
服务器异常:A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext, however instance members are not guaranteed to be thread safe. This could also be caused by a nested query being evaluated on the client, if this is the case rewrite the query avoiding nested invocations.
dbcontext是不可以跨线程处理同一个对象的事务的(或者简单理解为不要跨线程使用同一个dbcontext实例,同时进行并发的操作),你看一下是否有这样的问题。
如果一定要跨线程,必须要保持同一时间只有一个线程在使用。