@@ -55,6 +55,26 @@ public virtual async Task Two_similar_complex_properties_projected_with_split_qu
55
55
}
56
56
}
57
57
58
+ [ ConditionalFact ]
59
+ public virtual async Task Projecting_one_of_two_similar_complex_types_picks_the_correct_one ( )
60
+ {
61
+ var contextFactory = await InitializeAsync < Context32911_2 > ( seed : c => c . Seed ( ) ) ;
62
+
63
+ using var context = contextFactory . CreateContext ( ) ;
64
+
65
+ var query = context . Cs
66
+ . Where ( x => x . B . AId . Value == 1 )
67
+ . OrderBy ( x => x . Id )
68
+ . Take ( 10 )
69
+ . Select ( x => new
70
+ {
71
+ x . B . A . Id ,
72
+ x . B . Info . Created ,
73
+ } ) . ToList ( ) ;
74
+
75
+ Assert . Equal ( new DateTime ( 2000 , 1 , 1 ) , query [ 0 ] . Created ) ;
76
+ }
77
+
58
78
protected class Context32911 ( DbContextOptions options ) : DbContext ( options )
59
79
{
60
80
public DbSet < Offer > Offers { get ; set ; }
@@ -143,6 +163,69 @@ public class NestedEntity : EntityBase
143
163
public record Payment ( decimal Netto , decimal Brutto ) ;
144
164
}
145
165
166
+ protected class Context32911_2 ( DbContextOptions options ) : DbContext ( options )
167
+ {
168
+ public DbSet < A > As { get ; set ; }
169
+ public DbSet < B > Bs { get ; set ; }
170
+ public DbSet < C > Cs { get ; set ; }
171
+
172
+ protected override void OnModelCreating ( ModelBuilder modelBuilder )
173
+ {
174
+ modelBuilder . Entity < A > ( ) . Property ( x => x . Id ) . ValueGeneratedNever ( ) ;
175
+ modelBuilder . Entity < B > ( ) . Property ( x => x . Id ) . ValueGeneratedNever ( ) ;
176
+ modelBuilder . Entity < C > ( ) . Property ( x => x . Id ) . ValueGeneratedNever ( ) ;
177
+
178
+ modelBuilder . Entity < B > ( x => x . ComplexProperty ( b => b . Info ) . IsRequired ( ) ) ;
179
+ modelBuilder . Entity < C > ( x => x . ComplexProperty ( c => c . Info ) . IsRequired ( ) ) ;
180
+ }
181
+
182
+ public void Seed ( )
183
+ {
184
+ var c = new C
185
+ {
186
+ Id = 100 ,
187
+ Info = new Metadata { Created = new DateTime ( 2020 , 10 , 10 ) } ,
188
+ B = new B
189
+ {
190
+ Id = 10 ,
191
+ Info = new Metadata { Created = new DateTime ( 2000 , 1 , 1 ) } ,
192
+ A = new A { Id = 1 }
193
+ }
194
+ } ;
195
+
196
+ Cs . Add ( c ) ;
197
+ SaveChanges ( ) ;
198
+ }
199
+
200
+ public class Metadata
201
+ {
202
+ public DateTime Created { get ; set ; }
203
+ }
204
+
205
+ public class A
206
+ {
207
+ public int Id { get ; set ; }
208
+ }
209
+
210
+ public class B
211
+ {
212
+ public int Id { get ; set ; }
213
+ public Metadata Info { get ; set ; }
214
+ public int ? AId { get ; set ; }
215
+
216
+ public A A { get ; set ; }
217
+ }
218
+
219
+ public class C
220
+ {
221
+ public int Id { get ; set ; }
222
+ public Metadata Info { get ; set ; }
223
+ public int BId { get ; set ; }
224
+
225
+ public B B { get ; set ; }
226
+ }
227
+ }
228
+
146
229
#endregion
147
230
148
231
[ ConditionalTheory ]
0 commit comments