@@ -1269,7 +1269,7 @@ join eRoot in ctx.Entities.Include(e => e.Children)
1269
1269
on eVersion . RootEntityId equals eRoot . Id
1270
1270
into RootEntities
1271
1271
from eRootJoined in RootEntities . DefaultIfEmpty ( )
1272
- // ReSharper disable once ConstantNullCoalescingCondition
1272
+ // ReSharper disable once ConstantNullCoalescingCondition
1273
1273
select new { One = 1 , Coalesce = eRootJoined ?? ( eVersion ?? eRootJoined ) } ;
1274
1274
1275
1275
var result = query . ToList ( ) ;
@@ -1288,7 +1288,7 @@ join eRoot in ctx.Entities
1288
1288
on eVersion . RootEntityId equals eRoot . Id
1289
1289
into RootEntities
1290
1290
from eRootJoined in RootEntities . DefaultIfEmpty ( )
1291
- // ReSharper disable once ConstantNullCoalescingCondition
1291
+ // ReSharper disable once ConstantNullCoalescingCondition
1292
1292
select new
1293
1293
{
1294
1294
One = eRootJoined ,
@@ -1312,7 +1312,7 @@ join eRoot in ctx.Entities
1312
1312
on eVersion . RootEntityId equals eRoot . Id
1313
1313
into RootEntities
1314
1314
from eRootJoined in RootEntities . DefaultIfEmpty ( )
1315
- // ReSharper disable once MergeConditionalExpression
1315
+ // ReSharper disable once MergeConditionalExpression
1316
1316
#pragma warning disable IDE0029 // Use coalesce expression
1317
1317
select eRootJoined != null ? eRootJoined : eVersion ;
1318
1318
#pragma warning restore IDE0029 // Use coalesce expression
@@ -6862,6 +6862,75 @@ public BugContext18759(DbContextOptions options)
6862
6862
6863
6863
#endregion
6864
6864
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
+
6865
6934
private DbContextOptions _options ;
6866
6935
6867
6936
private SqlServerTestStore CreateTestStore < TContext > (
0 commit comments