The operation cannot be completed because the DbContext has been disposed
See original GitHub issueI use abp 2.0.2. The exception as follow:
The operation cannot be completed because the DbContext has been disposed.
在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
在 System.Data.Entity.Internal.Linq.DbQueryProvider.System.Data.Entity.Infrastructure.IDbAsyncQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
在 System.Data.Entity.QueryableExtensions.CountAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
在 System.Data.Entity.QueryableExtensions.CountAsync[TSource](IQueryable`1 source)
在 ZTO.UserAnalysis.UserInformation.UserInformationAppService.<SyncDataFromOrder>d__4.MoveNext() 位置 E:\ztoSource\UserAnalysis\ZTO.UserAnalysis.Application\UserInformation\UserInformationAppService.cs:行号 45
In application method, I set UnitOfWork`s IsDisabled to true, and i call repository in the method.
My code is bellow:
[UnitOfWork(IsDisabled = true)]
public async Task SyncDataFromOrder(DateTime from, DateTime to)
{
var orderQuery = _orderRepository.GetAll().Where(i => i.CreationTime >= from && i.CreationTime <= to).OrderBy(i => i.CreationTime);
var querySize = await orderQuery.CountAsync();
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (12 by maintainers)
Top Results From Across the Web
c# - The operation cannot be completed because ...
Since this dataContext has been disposed, it is no longer valid, and .ToList() throws an exception. That is the "why it doesn't work"....
Read more >Re: Error message: The operation cannot be completed ...
This fails because the DbContext has been disposed. ... There are several options to solve this: 1) Turn off lazy loading: The navigation...
Read more >Because the DbContext has been disposed. #238
The operation cannot be completed because the DbContext has been disposed. Description: An unhandled exception occurred during the execution of the current web ......
Read more >The operation cannot be completed because ...
The operation cannot be completed because the DbContext has been disposed. The operation cannot be completed because the DbContext has been disposed.
Read more >The operation cannot be completed because ...
The DBContext was disposed when I called ProjectManager.ConvertProjects method, so when I called otherDataManager.Load , it does not work.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see. It need’s to be virtual, or injected using the interface version. I think that is what I have been missing then. Thanks @acjh!
Show code.