question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Asynchronous operation Repository

See original GitHub issue

ABP 1.4.1

var query = _userTypeRepository.GetAll();
var total =  query.CountAsync();
var rows =  query.Skip(input.Rows * (input.Page - 1)).Take(input.Rows).ToListAsync();
return new GetXXXOutput { Total = await total, Rows = await rows };

The above code will randomly appear the following error:


"Unexpected connection state. When using a wrapping provider ensure that the StateChange event is implemented on the wrapped DbConnection."
"A second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. Any instance members are not guaranteed to be thread safe."
"An error occurred while executing the command definition. See the inner exception for details."

It seems that EF DBContext is not thread safe, if we want to abp in the data on the operation, there is any good way?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hikalkancommented, Mar 2, 2017

BTW, Async pattern’s advantage is not multi-threading. It’s a different topic.

1reaction
hikalkancommented, Mar 2, 2017

You missed “await” keywords for CountAsync and ToListAsync

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asynchronous Generic Repository in ASP.NET Core Web API
Async programming is a parallel programming technique, which allows the working process to run separately from the main application thread. As ...
Read more >
domain driven design - Are repositories async?
@Ced, it is entirely possible to provide a synchronous interface to an inherently async operation. It just means that whatever waiting needs to ......
Read more >
Async Programming in C# Repository Pattern
To create an asynchronous API, you need to make all the methods from start to end asynchronous. Asynchronous is actually beneficial for I/O ......
Read more >
Implementing an async Repository and Unit of Work with ...
This article explains how to implement the Repository and Unit of Work patterns in .NET Core applications, exposing an asynchronous interface ...
Read more >
Asynchronous Programming - EF Core
Async operations are important for keeping a responsive UI in rich client applications, and can also increase throughput in web applications ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found