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.

2.2 -> 5.0.5 (.Net Core 3.1) strange subquery in simple select with Include

See original GitHub issue

I’ve first posted to npgsql (https://github.com/npgsql/efcore.pg/issues/1808), but it works the same with sqlite

var deliveryChannel = dbContext.DeliveryChannel.AsNoTrackingWithIdentityResolution().Include(c => c.ClientData).ThenInclude(c => c.DeliveryChannel).Where(c => (c.State == State.Active && c.ExtendedData == "someData") ).OrderByDescending(d => d.Id).FirstOrDefaultAsync().Result;

ClientData has a collection of DeliveryChannels. I’m selecting all DeliveryChannels from the Client of some exact DeliveryChannel (why not? 😃 ).

and it produces strange subquery in first select of split query (in EF 2.2 there is no subquery):

image

public class ClientData
{
...
 public virtual ICollection<DeliveryChannel> DeliveryChannel { get; set; }
}

public class DeliveryChannel{
...
      public int ClientDataId { get; set; }
      public ClientData ClientData { get; set; }
}

options.UseSqlite("Data Source=sqlitedemo.db", p => p.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery));

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
freerider7777commented, Apr 24, 2021

@smitpatel Do you know sql? 😃 Have a look at the underlined lines (in the picture) and you will see that inner select is with limit 1, so it is not needed to do subquery and order by in outer query. In 2.2 it was a simple select without subquery. It’a pity EF is not consistent and every new version brings some hidden surprises…

1reaction
smitpatelcommented, Apr 29, 2021

It requires some big changes happened in 6.0 so sadly the earlier release will be 6.0-preview5

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Core 5 - Does the order of Include()/Where() methods in ...
When this runs in EF Core 3.1 (2.2 and 3.0 are similar) it generates a SQL statement with two subqueries, one to join...
Read more >
Migrate from ASP.NET Core 3.1 to 5.0
Learn how to migrate an ASP.NET Core 3.1 project to ASP.NET Core 5.0.
Read more >
Using a Subquery in a SELECT statement - Simple Talk
When a SELECT statement is embedded within another statement it is known as a subquery. There are two types of subqueries: basic subquery...
Read more >
Appendix C. MySQL Change History
This appendix lists the changes from version to version in the MySQL source code through the latest version of MySQL 6.0, which is...
Read more >
SQL Injection
A vulnerability, which was classified as critical, has been found in SourceCodester Simple Chat System 1.0. Affected by this issue is some unknown...
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