I am experiencing what seems to be an edge case bug, when doing a Linq query, combining joins and an EXISTS clause on a view.
I'll try to explain with examples.
3 entities and one view is involved
- MasterEntity (id, text)
- Detail1Entity (id)
- Detail2Entity (id)
- AccessView (id) -TypedView
I want to perform a query as such:
var q = from m in linqMetaData.Master
where linqMetaData.Accessview.Any(x => x.Id == m.Id)
join d1 in linqMetaData.Detail1 on m.Id equals d1.Id into join1
join d2 in linqMetaData.Detail2 on m.Id equals d2.Id into join2
from j1 in join1.DefaultIfEmpty()
from j2 in join2.DefaultIfEmpty()
select m.Text;
var rows = await q.ToListAsync();
However, I get exception which state it is referencing non existing column: column LPA_L1.text does not exist. The query is:
SELECT "LPA_L1"."text" as "Text"
from
((
select
"LPA_L1"."text" as "Text"
from
((
select
"LPA_L5"."id" as "Id",
:p2 as "LPFA_6"
from
("public"."master" "LPA_L4"
left join "public"."detail1" "LPA_L5" on
"LPA_L4"."id" = "LPA_L5"."id")
where
( exists (
select
"LPA_L6"."Id"
from
(
select
"LPLA_2"."id" as "Id"
from
"public"."accessview" "LPLA_2") "LPA_L6"
where
( ( "LPA_L6"."Id" = "LPA_L4"."id"))))) "LPA_L1"
left join "public"."detail2" "LPA_L2" on
"LPA_L1"."Id" = "LPA_L2"."id")
However, if I change code generation so the access view is an entity instead of a typed view, the same query works, with the expected query generated as:
select
"LPA_L1"."text" as "Text"
from
(("public"."master" "LPA_L1"
left join "public"."detail1" "LPA_L2" on
"LPA_L1"."id" = "LPA_L2"."id")
left join "public"."detail2" "LPA_L3" on
"LPA_L1"."id" = "LPA_L3"."id")
where
( ( ( exists (
select
"LPLA_2"."id" as "Id"
from
"public"."accessview2" "LPLA_2"
where
( ( "LPLA_2"."id" = "LPA_L1"."id"))))))
Also note, that the problem only exists when I am having 2 joins. I can also solve the issue by removing one of the joins (but I need both).
I am using LLBLGen 5.8.1.