-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed
Milestone
Description
query:
l1s => l1s.Where(l1 => l1.OneToOne_Optional_FK.OneToMany_Optional.Distinct().Select(l3 => l3.Id).Contains(1))
query model before nav-rewrite:
from Level1 l1 in DbSet<Level1>
where
(from Level3 l3 in
(from Level3 <generated>_2 in l1.OneToOne_Optional_FK.OneToMany_Optional
select <generated>_2)
.Distinct()
select l3.Id)
.Contains(1)
select l1
query model after nav-rewrite:
from Level1 l1 in DbSet<Level1>
join Level2 l1.OneToOne_Optional_FK in DbSet<Level2>
on (Nullable<int>) Property(l1, "Id") equals Property(l1.OneToOne_Optional_FK, "Level1_Optional_Id") into l1.OneToOne_Optional_FK_group
from Level2 l1.OneToOne_Optional_FK in
(from Level2 l1.OneToOne_Optional_FK_groupItem in l1.OneToOne_Optional_FK_group
select l1.OneToOne_Optional_FK_groupItem)
.DefaultIfEmpty()
where
(from Level3 l3 in
(from Level3 <generated>_2 in DbSet<Level3>
where (Nullable<int>) Property(l1.OneToOne_Optional_FK, "Id") == Property(<generated>_2, "OneToMany_Optional_InverseId")
select <generated>_2)
.Distinct()
select l3.Id)
.Contains(1)
select l1
Problem here is that we don't introduce null check for left key access of
where (Nullable<int>) Property(l1.OneToOne_Optional_FK, "Id") == Property(<generated>_2, "OneToMany_Optional_InverseId")
l1.OneToOne_Optional_FK
is optional navigation, so the key access could cause null ref.
This is only problem for InMemory - when we introduce the null check we need to make sure that this null check will be optimized for relational, so that we don't get worse queries.