-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Count() times out on IQueryable #29224
Comments
Can you please post the SQL EF is generating? You can do this by turning on logging (see docs). |
|
@stesvis that doesn't look like a LINQ query which ends with a Count - can you please double-check which query exactly you're executing? The query with Count should be only projecting the count out. For regular, non-Count queries, you may want to take a look at single vs. split queries, especially if each Customer typically has lots of Clients and AspNetUsers. |
@roji I added this to my protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.LogTo(Console.WriteLine);
} |
You'll have to post a runnable code sample, it's hard to help given just a code snippet. |
Each Customer only has one Client and one AspNetUser; they're reference navigations. Due to this bug #29182 split query may be slower in this instance. |
@roji got the query finally:
|
@stesvis your logs above indicate that the query took 10ms ( |
That's the query. I was testing it locally and had a breakpoint on |
@stesvis there's not really much I can do to help... Since the timeout doesn't always occur, that points towards some environmental issue, e.g. your network being flaky in some way. If it occurs often, I'd try to first see the actual timeout occuring in the EF logs as above, including the timing - that would provide clear proof of the issue. At that point you can investigate if there was a network outage or similar at the same time, or possibly some database availability issue... |
But if i am debugging this locally how can I be a network issue?
I don't understand how this only happens with EF Core and not with EF6. |
Can you please post the SQL being generated by EF6, to rule out any SQL differences that may be the source of the difference? |
This is the equivalent query generated by the same method in EF6:
|
@stesvis It seems highly unlikely that this is related to EF Core rather than some other environment difference. Can you post two complete samples, one with EF6 and one with EF Core, so we can compare concrete differences? |
I finally found the problem. But this might be a VS2022 issue. Specifically VS2022 was taking 3.6GB, which I think is a lot but I've used VS2019 until a couple of weeks ago. |
I am performing a query to the
Customers
table with some filters:Then I want to get the count (for pagination labels):
And when the query returns a high number (3-4 thousands records), it often times out with this error (from the logs):
IMPORTANT: The same approach never times out in the old Entity Framework 6, I only noticed it in EF Core 6 because I am rebuilding it with the new .NET Core.
Any ideas?
Provider and version information
EF Core version: 6.0.9
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows
IDE: Visual Studio 2022 17.3.2
The text was updated successfully, but these errors were encountered: