I've got a problem with eager-loading.
In short, there are 3 tables. tableA (parent), tableB (child) and tableC (grandchild).
After a SELECT and ToList, accessing tableC will cause a lot of no-needed SELECT's (=> getting slow).
Checking the generated first SQL, all the information from tableC are included. So it's confusing why all the subsequents SELECT's to tableC are initiated (and making the program SLOW)?
The (simplified) generated SQL:
Code: Select all
SELECT t1."Id", t1..., t3."Id" AS "Id1", t3..., t4."Id" AS "Id2", t4...
FROM (
SELECT t2."Id", t2...
FROM "tableA" t2
WHERE (t2."someColumn" = :p0)
) t1
LEFT OUTER JOIN ("tableB" t3
LEFT OUTER JOIN "tableC" t4 ON t3."Id" = t4."tableB_Id") ON t1."Id" = t3."tableA_Id"
ORDER BY t1."Id", t3."Id"
Code: Select all
SELECT t1."Id", t1...
FROM "tableC" t1
WHERE :np0 = t1."tableB_Id"
-- np0: Input BigInt (Size = 0; DbType = Int64) [73361]
-- Context: Devart.Data.PostgreSql.Linq.Provider.PgSqlDataProvider Mapping: AttributeMappingSource Build: 4.8.1471.0
SELECT t1."Id", t1...
FROM "tableC" t1
WHERE :np0 = t1."tableB_Id"
-- np0: Input BigInt (Size = 0; DbType = Int64) [73362]
-- Context: Devart.Data.PostgreSql.Linq.Provider.PgSqlDataProvider Mapping: AttributeMappingSource Build: 4.8.1471.0
Code: Select all
var queryTableA = context.TableAs
.LoadWith(a => a.TableBs
.LoadWith(b => b.TableCs, FetchMode.Join), FetchMode.Join)
.Where(a => a.someColumn==myCodeValue)
.OrderBy(a => a.Id)
.Select(a => a).ToList();
Kind regards, Ole