One-to-many projection creates many subqueries
See original GitHub issueFirst of all - this tool practically saved my life when migrating from EF6 to EF Core, great job, everything works better than EF Core, instead of one thing
LinqToDB.Common.Configuration.Linq.AllowMultipleQuery = true;
var querySample = db.TicketNumbers.Where(p => p.Ticket.Name == "Lacna").Select(p => new
{
Id = p.Id,
TicketName = p.Ticket.Name,
CustomFields = p.CustomFieldValues.Select(cf => new
{
Name = cf.CustomFieldDefinition.Name,
Value = cf.Value
}).ToList()
}).ToLinqToDB().ToList();
This guery yields back 300 results, from the logging it seems that Linq2Db core runs the subquery for each of the obtained item. [= 300 subqueries, 300 roundtrips to the DB]. For our scenario, for example, this creates an issue as our SQL Server is physically located elsewhere than the calling app creating a huge performance gap due to the latency, but I believe this might be an issue for other scenarios too (running 301 queries when in fact only 2 are needed)
From observing the logs EF Core handles this differently - running a single subquery on the very same condition as main “root” query, effectively creating only one more roundtrip to the DB, then linking the data based on their foreign-key declaration.
To sum it up, I have 3 questions:
- Is there anything I can do to change the one-to-many behavior?
- Are there any plans to change the subdata loading routine?
- If I wanted to hack a solution for our needs by changing the Linq2Db core, could you advise me where should I look?
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (8 by maintainers)
Top GitHub Comments
@brunolau, good news there. I had created first Eager Loading prototype using current sources and It looks very promising, later will point to PR which introduces this feature. A lot of work here but i hope in one or two weeks it will be done.
I hope tomorrow.