Closed komdil closed 2 years ago
Using a wrapping IQueryProvider
is not recommended for this, as you would need to reimplement a lot of EF Core functionality to make it work as intended.
Consider using separate DbContext
instances via DbContextFactory
I found another way to implement this. But I don't think it is a good idea. However, we can use in some use cases: https://github.com/komdil/efcoreMultiThreadingContext
I have some scenarios related to getting entities from the database that I need to use one DbContext in multiple threads. I want to implement a queue for DbContext. I tried to do this by implementing IQuerable to a new class and lock query provider. It is working in some use cases, but I am still getting the error A
second operation was started on this context before a previous operation completed...
in some use casesHere is my workaround:
GetEntities method:
This workaround is working for getting a single entity. Here is the usage:
I know DbContext has not supported multithreading, but in some use cases, I really need it. When the first operation is not completed I want the second operation to wait till completion. Is there any way to implement this? My workaround is working only for getting single entity and I am getting error on Where, Select... queries EF Core version: Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Target framework: (e.g. .NET 5.0) Operating system: IDE: (e.g. Visual Studio 2019 16.3)