Skip to content

Commit 6833f48

Browse files
committed
Add regression test for #19138
1 parent 414c070 commit 6833f48

File tree

1 file changed

+72
-3
lines changed

1 file changed

+72
-3
lines changed

test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ join eRoot in ctx.Entities.Include(e => e.Children)
12691269
on eVersion.RootEntityId equals eRoot.Id
12701270
into RootEntities
12711271
from eRootJoined in RootEntities.DefaultIfEmpty()
1272-
// ReSharper disable once ConstantNullCoalescingCondition
1272+
// ReSharper disable once ConstantNullCoalescingCondition
12731273
select new { One = 1, Coalesce = eRootJoined ?? (eVersion ?? eRootJoined) };
12741274

12751275
var result = query.ToList();
@@ -1288,7 +1288,7 @@ join eRoot in ctx.Entities
12881288
on eVersion.RootEntityId equals eRoot.Id
12891289
into RootEntities
12901290
from eRootJoined in RootEntities.DefaultIfEmpty()
1291-
// ReSharper disable once ConstantNullCoalescingCondition
1291+
// ReSharper disable once ConstantNullCoalescingCondition
12921292
select new
12931293
{
12941294
One = eRootJoined,
@@ -1312,7 +1312,7 @@ join eRoot in ctx.Entities
13121312
on eVersion.RootEntityId equals eRoot.Id
13131313
into RootEntities
13141314
from eRootJoined in RootEntities.DefaultIfEmpty()
1315-
// ReSharper disable once MergeConditionalExpression
1315+
// ReSharper disable once MergeConditionalExpression
13161316
#pragma warning disable IDE0029 // Use coalesce expression
13171317
select eRootJoined != null ? eRootJoined : eVersion;
13181318
#pragma warning restore IDE0029 // Use coalesce expression
@@ -6862,6 +6862,75 @@ public BugContext18759(DbContextOptions options)
68626862

68636863
#endregion
68646864

6865+
#region Issue19138
6866+
6867+
[ConditionalFact]
6868+
public void Accessing_scalar_property_in_derived_type_projection_does_not_load_owned_navigations()
6869+
{
6870+
using var _ = CreateDatabase19138();
6871+
using var context = new BugContext19138(_options);
6872+
6873+
var result = context.BaseEntities
6874+
.Select(b => context.OtherEntities.Where(o => o.OtherEntityData == ((SubEntity19138)b).Data).FirstOrDefault())
6875+
.ToList();
6876+
6877+
AssertSql(
6878+
@"SELECT [p].[Id], [p].[UserDeleteId]
6879+
FROM [People] AS [p]
6880+
LEFT JOIN [User19138] AS [u] ON [p].[UserDeleteId] = [u].[Id]
6881+
WHERE [u].[Id] IS NOT NULL");
6882+
}
6883+
6884+
private SqlServerTestStore CreateDatabase19138()
6885+
=> CreateTestStore(
6886+
() => new BugContext19138(_options),
6887+
context =>
6888+
{
6889+
ClearLog();
6890+
});
6891+
6892+
private class BaseEntity19138
6893+
{
6894+
public int Id { get; set; }
6895+
}
6896+
6897+
private class SubEntity19138 : BaseEntity19138
6898+
{
6899+
public string Data { get; set; }
6900+
public Owned19138 Owned { get; set; }
6901+
}
6902+
6903+
private class Owned19138
6904+
{
6905+
public string OwnedData { get; set; }
6906+
}
6907+
6908+
private class OtherEntity19138
6909+
{
6910+
public string Id { get; set; }
6911+
public string OtherEntityData { get; set; }
6912+
}
6913+
6914+
private class BugContext19138 : DbContext
6915+
{
6916+
public DbSet<BaseEntity19138> BaseEntities { get; set; }
6917+
public DbSet<OtherEntity19138> OtherEntities { get; set; }
6918+
6919+
protected override void OnModelCreating(ModelBuilder modelBuilder)
6920+
{
6921+
modelBuilder.Entity<BaseEntity19138>();
6922+
modelBuilder.Entity<SubEntity19138>().OwnsOne(se => se.Owned);
6923+
modelBuilder.Entity<OtherEntity19138>();
6924+
}
6925+
6926+
public BugContext19138(DbContextOptions options)
6927+
: base(options)
6928+
{
6929+
}
6930+
}
6931+
6932+
#endregion
6933+
68656934
private DbContextOptions _options;
68666935

68676936
private SqlServerTestStore CreateTestStore<TContext>(

0 commit comments

Comments
 (0)