-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
ComplexNavigationsQueryTestBase.cs
4131 lines (3763 loc) · 179 KB
/
ComplexNavigationsQueryTestBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.CodeDom.Compiler;
using Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel;
#pragma warning disable RCS1155 // Use StringComparison when comparing strings.
namespace Microsoft.EntityFrameworkCore.Query;
#nullable disable
public abstract class ComplexNavigationsQueryTestBase<TFixture> : QueryTestBase<TFixture>
where TFixture : ComplexNavigationsQueryFixtureBase, new()
{
protected ComplexNavigationsContext CreateContext()
=> Fixture.CreateContext();
protected ComplexNavigationsQueryTestBase(TFixture fixture)
: base(fixture)
{
}
protected override Expression RewriteExpectedQueryExpression(Expression expectedQueryExpression)
=> new ExpectedQueryRewritingVisitor(Fixture.GetShadowPropertyMappings()).Visit(expectedQueryExpression);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Entity_equality_empty(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Where(l => l.OneToOne_Optional_FK1 == new Level2()),
assertEmpty: true);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_when_sentinel_ef_property(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Where(l => EF.Property<int>(l.OneToOne_Optional_FK1, "Id") == 0),
assertEmpty: true);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_using_property_method_required(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Where(l => EF.Property<int>(l.OneToOne_Required_FK1, "Id") > 7));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_using_property_method_required2(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level2>().Where(l => EF.Property<int>(l.OneToOne_Required_FK_Inverse2, "Id") > 7));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_using_property_method_nested(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Where(l => EF.Property<int>(EF.Property<Level2>(l, "OneToOne_Required_FK1"), "Id") == 7));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_using_property_method_nested2(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level2>().Where(l => EF.Property<int>(EF.Property<Level1>(l, "OneToOne_Required_FK_Inverse2"), "Id") == 7));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_using_property_method_and_member_expression1(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Where(l => EF.Property<Level2>(l, "OneToOne_Required_FK1").Id == 7));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_using_property_method_and_member_expression2(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Where(l => EF.Property<int>(l.OneToOne_Required_FK1, "Id") == 7));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_using_property_method_and_member_expression3(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level2>().Where(l => EF.Property<int>(l.OneToOne_Required_FK_Inverse2, "Id") == 7));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_navigation_converted_to_FK(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level2>().Where(l => l.OneToOne_Required_FK_Inverse2 == new Level1 { Id = 1 }),
ss => ss.Set<Level2>().Where(l => l.OneToOne_Required_FK_Inverse2.Id == 1));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_two_conditions_on_same_navigation(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Where(
l => l.OneToOne_Required_FK1 == new Level2 { Id = 1 }
|| l.OneToOne_Required_FK1 == new Level2 { Id = 2 }),
ss => ss.Set<Level1>().Where(
l => l.OneToOne_Required_FK1.Id == 1
|| l.OneToOne_Required_FK1.Id == 2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Key_equality_two_conditions_on_same_navigation2(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level2>().Where(
l => l.OneToOne_Required_FK_Inverse2 == new Level1 { Id = 1 }
|| l.OneToOne_Required_FK_Inverse2 == new Level1 { Id = 2 }),
ss => ss.Set<Level2>().Where(
l => l.OneToOne_Required_FK_Inverse2.Id == 1
|| l.OneToOne_Required_FK_Inverse2.Id == 2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Multi_level_include_with_short_circuiting(bool async)
{
using var context = CreateContext();
var query = context.Fields
.Include(x => x.Label.Globalizations)
.ThenInclude(x => x.Language)
.Include(x => x.Placeholder.Globalizations)
.ThenInclude(x => x.Language);
var result = (async ? await query.ToListAsync() : query.ToList()).OrderBy(e => e.Name).ToList();
Assert.Equal(2, result.Count);
Assert.Equal("Field1", result[0].Name);
Assert.Equal("Field2", result[1].Name);
Assert.Equal("MLS1", result[0].Label.DefaultText);
Assert.Equal("MLS3", result[1].Label.DefaultText);
Assert.Null(result[0].Placeholder);
Assert.Equal("MLS4", result[1].Placeholder.DefaultText);
var globalizations_0_label = result[0].Label.Globalizations.OrderBy(g => g.Text).ToList();
Assert.Equal(3, globalizations_0_label.Count);
Assert.Equal("Globalization0", globalizations_0_label[0].Text);
Assert.Equal("Language0", globalizations_0_label[0].Language.Name);
Assert.Equal("Globalization1", globalizations_0_label[1].Text);
Assert.Equal("Language1", globalizations_0_label[1].Language.Name);
Assert.Equal("Globalization2", globalizations_0_label[2].Text);
Assert.Equal("Language2", globalizations_0_label[2].Language.Name);
var globalizations_1_label = result[1].Label.Globalizations.OrderBy(g => g.Text).ToList();
Assert.Equal(3, globalizations_1_label.Count);
Assert.Equal("Globalization6", globalizations_1_label[0].Text);
Assert.Equal("Language6", globalizations_1_label[0].Language.Name);
Assert.Equal("Globalization7", globalizations_1_label[1].Text);
Assert.Equal("Language7", globalizations_1_label[1].Language.Name);
Assert.Equal("Globalization8", globalizations_1_label[2].Text);
Assert.Equal("Language8", globalizations_1_label[2].Language.Name);
var globalizations_1_placeholder = result[1].Placeholder.Globalizations.OrderBy(g => g.Text).ToList();
Assert.Single(globalizations_1_placeholder);
Assert.Equal("Globalization9", globalizations_1_placeholder[0].Text);
Assert.Equal("Language9", globalizations_1_placeholder[0].Language.Name);
}
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_key_access_optional(bool async)
=> AssertQuery(
async,
ss => from e1 in ss.Set<Level1>()
join e2 in ss.Set<Level2>() on e1.Id equals e2.OneToOne_Optional_FK_Inverse2.Id
select new { Id1 = e1.Id, Id2 = e2.Id },
e => (e.Id1, e.Id2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_key_access_required(bool async)
=> AssertQuery(
async,
ss => from e1 in ss.Set<Level1>()
join e2 in ss.Set<Level2>() on e1.Id equals e2.OneToOne_Required_FK_Inverse2.Id
select new { Id1 = e1.Id, Id2 = e2.Id },
e => (e.Id1, e.Id2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Navigation_key_access_optional_comparison(bool async)
=> AssertQueryScalar(
async,
ss => from e2 in ss.Set<Level2>()
where e2.OneToOne_Optional_PK_Inverse2.Id > 5
select e2.Id);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Simple_level1_include(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Include(l1 => l1.OneToOne_Required_PK1));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Simple_level1(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>());
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Simple_level1_level2_include(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Include(l1 => l1.OneToOne_Required_PK1.OneToOne_Required_PK2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Simple_level1_level2_GroupBy_Count(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<Level1>().GroupBy(
l1 => l1.OneToOne_Required_PK1.OneToOne_Required_PK2.Name)
.Select(g => g.Count()));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Simple_level1_level2_GroupBy_Having_Count(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<Level1>().GroupBy(
l1 => l1.OneToOne_Required_PK1.OneToOne_Required_PK2.Name,
l1 => new { Id = (int?)l1.OneToOne_Required_PK1.Id ?? 0 })
.Where(g => g.Min(l1 => l1.Id) > 0)
.Select(g => g.Count()));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Simple_level1_level2_level3_include(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Include(l1 => l1.OneToOne_Required_PK1.OneToOne_Required_PK2.OneToOne_Required_PK3));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Navigation_key_access_required_comparison(bool async)
=> AssertQueryScalar(
async,
ss => from e2 in ss.Set<Level2>()
where e2.OneToOne_Required_PK_Inverse2.Id > 5
select e2.Id);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Navigation_inside_method_call_translated_to_join(bool async)
=> AssertQuery(
async,
ss => from e1 in ss.Set<Level1>()
where e1.OneToOne_Required_FK1.Name.StartsWith("L")
select e1,
ss => from e1 in ss.Set<Level1>()
where e1.OneToOne_Required_FK1.Name.MaybeScalar(x => x.StartsWith("L")) == true
select e1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Navigation_inside_method_call_translated_to_join2(bool async)
=> AssertQuery(
async,
ss => from e3 in ss.Set<Level3>()
where e3.OneToOne_Required_FK_Inverse3.Name.StartsWith("L")
select e3);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Optional_navigation_inside_method_call_translated_to_join(bool async)
=> AssertQuery(
async,
ss => from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.Name.StartsWith("L")
select e1,
ss => from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.Name.MaybeScalar(x => x.StartsWith("L")) == true
select e1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Optional_navigation_inside_property_method_translated_to_join(bool async)
=> AssertQuery(
async,
ss => from e1 in ss.Set<Level1>()
where EF.Property<string>(EF.Property<Level2>(e1, "OneToOne_Optional_FK1"), "Name") == "L2 01"
select e1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Optional_navigation_inside_nested_method_call_translated_to_join(bool async)
=> AssertQuery(
async,
ss => from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.Name.ToUpper().StartsWith("L")
select e1,
ss => from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.Name.MaybeScalar(x => x.ToUpper().StartsWith("L"))
== true
select e1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Method_call_on_optional_navigation_translates_to_null_conditional_properly_for_arguments(bool async)
=> AssertQuery(
async,
ss => from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.Name.StartsWith(e1.OneToOne_Optional_FK1.Name)
select e1,
ss => from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.Name.MaybeScalar(x => x.StartsWith(e1.OneToOne_Optional_FK1.Name)) == true
select e1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Optional_navigation_inside_method_call_translated_to_join_keeps_original_nullability(bool async)
=> AssertQuery(
async,
ss =>
from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.Date.AddDays(10) > new DateTime(2000, 2, 1)
select e1,
ss =>
from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.MaybeScalar(x => x.Date.AddDays(10)) > new DateTime(2000, 2, 1)
select e1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Optional_navigation_inside_nested_method_call_translated_to_join_keeps_original_nullability(bool async)
=> AssertQuery(
async,
ss =>
from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.Date.AddDays(10).AddDays(15).AddMonths(2) > new DateTime(2002, 2, 1)
select e1,
ss =>
from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.MaybeScalar(x => x.Date.AddDays(10).AddDays(15).AddMonths(2)) > new DateTime(2000, 2, 1)
select e1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Optional_navigation_inside_nested_method_call_translated_to_join_keeps_original_nullability_also_for_arguments(
bool async)
=> AssertQuery(
async,
ss =>
from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.Date.AddDays(15).AddDays(e1.OneToOne_Optional_FK1.Id) > new DateTime(2002, 2, 1)
select e1,
ss =>
from e1 in ss.Set<Level1>()
where e1.OneToOne_Optional_FK1.MaybeScalar(x => x.Date.AddDays(15).AddDays(x.Id)) > new DateTime(2000, 2, 1)
select e1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_in_outer_selector_translated_to_extra_join(bool async)
=> AssertQuery(
async,
ss => from e1 in ss.Set<Level1>()
join e2 in ss.Set<Level2>() on e1.OneToOne_Optional_FK1.Id equals e2.Id
select new { Id1 = e1.Id, Id2 = e2.Id },
e => (e.Id1, e.Id2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_in_outer_selector_translated_to_extra_join_nested(bool async)
=> AssertQuery(
async,
ss => from e1 in ss.Set<Level1>()
join e3 in ss.Set<Level3>() on e1.OneToOne_Required_FK1.OneToOne_Optional_FK2.Id equals e3.Id
select new { Id1 = e1.Id, Id3 = e3.Id },
e => (e.Id1, e.Id3));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_in_outer_selector_translated_to_extra_join_nested2(bool async)
=> AssertQuery(
async,
ss => from e3 in ss.Set<Level3>()
join e1 in ss.Set<Level1>() on e3.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK_Inverse2.Id equals e1.Id
select new { Id3 = e3.Id, Id1 = e1.Id },
e => (e.Id1, e.Id3));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_in_inner_selector(bool async)
=> AssertQuery(
async,
ss => from e2 in ss.Set<Level2>()
join e1 in ss.Set<Level1>() on e2.Id equals e1.OneToOne_Optional_FK1.Id
select new { Id2 = e2.Id, Id1 = e1.Id },
e => (e.Id2, e.Id1));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigations_in_inner_selector_translated_without_collision(bool async)
=> AssertQuery(
async,
ss => from e2 in ss.Set<Level2>()
join e1 in ss.Set<Level1>() on e2.Id equals e1.OneToOne_Optional_FK1.Id
join e3 in ss.Set<Level3>() on e2.Id equals e3.OneToOne_Optional_FK_Inverse3.Id
select new
{
Id2 = e2.Id,
Id1 = e1.Id,
Id3 = e3.Id
},
e => (e.Id2, e.Id1, e.Id3));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_non_key_join(bool async)
=> AssertQuery(
async,
ss =>
from e2 in ss.Set<Level2>()
join e1 in ss.Set<Level1>() on e2.Name equals e1.OneToOne_Optional_FK1.Name
select new
{
Id2 = e2.Id,
Name2 = e2.Name,
Id1 = e1.Id,
Name1 = e1.Name
},
e => (e.Id2, e.Name2, e.Id1, e.Name1));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_with_orderby_on_inner_sequence_navigation_non_key_join(bool async)
=> AssertQuery(
async,
ss =>
from e2 in ss.Set<Level2>()
join e1 in ss.Set<Level1>().OrderBy(l1 => l1.Id) on e2.Name equals e1.OneToOne_Optional_FK1.Name
select new
{
Id2 = e2.Id,
Name2 = e2.Name,
Id1 = e1.Id,
Name1 = e1.Name
},
e => (e.Id2, e.Name2, e.Id1, e.Name1));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_self_ref(bool async)
=> AssertQuery(
async,
ss => from e1 in ss.Set<Level1>()
join e2 in ss.Set<Level1>() on e1.Id equals e2.OneToMany_Optional_Self_Inverse1.Id
select new { Id1 = e1.Id, Id2 = e2.Id },
e => (e.Id1, e.Id2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_nested(bool async)
=> AssertQuery(
async,
ss => from e3 in ss.Set<Level3>()
join e1 in ss.Set<Level1>() on e3.Id equals e1.OneToOne_Required_FK1.OneToOne_Optional_FK2.Id
select new { Id3 = e3.Id, Id1 = e1.Id },
e => (e.Id3, e.Id1));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_nested2(bool async)
=> AssertQuery(
async,
ss => from e3 in ss.Set<Level3>()
join e1 in ss.Set<Level1>().OrderBy(ll => ll.Id) on e3.Id equals e1.OneToOne_Required_FK1.OneToOne_Optional_FK2.Id
select new { Id3 = e3.Id, Id1 = e1.Id },
e => (e.Id3, e.Id1));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_deeply_nested_non_key_join(bool async)
=> AssertQuery(
async,
ss =>
from e4 in ss.Set<Level4>()
join e1 in ss.Set<Level1>() on e4.Name equals e1.OneToOne_Required_FK1.OneToOne_Optional_FK2.OneToOne_Required_PK3.Name
select new
{
Id4 = e4.Id,
Name4 = e4.Name,
Id1 = e1.Id,
Name1 = e1.Name
},
e => (e.Id4, e.Name4, e.Id1, e.Name1));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_navigation_deeply_nested_required(bool async)
=> AssertQuery(
async,
ss =>
from e1 in ss.Set<Level1>()
join e4 in ss.Set<Level4>() on e1.Name equals e4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3
.OneToOne_Required_PK_Inverse2.Name
select new
{
Id4 = e4.Id,
Name4 = e4.Name,
Id1 = e1.Id,
Name1 = e1.Name
},
e => (e.Id4, e.Name4, e.Id1, e.Name1));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Include_reference_and_project_into_anonymous_type(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Include(e => e.OneToOne_Optional_FK1).Select(e => new { e.Id, entity = e }),
elementSorter: e => e.Id,
elementAsserter: (e, a) =>
{
AssertInclude(e.entity, a.entity, new ExpectedInclude<Level1>(ee => ee.OneToOne_Optional_FK1));
AssertEqual(e.Id, a.Id);
});
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_nav_prop_reference_optional1(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Select(e => e.OneToOne_Optional_FK1.Name));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_nav_prop_reference_optional1_via_DefaultIfEmpty(bool async)
=> AssertQuery(
async,
ss =>
from l1 in ss.Set<Level1>()
join l2 in ss.Set<Level2>() on l1.Id equals l2.Level1_Optional_Id into groupJoin
from l2 in groupJoin.DefaultIfEmpty()
select l2 == null ? null : l2.Name);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_nav_prop_reference_optional2(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<Level1>().Select(e => (int?)e.OneToOne_Optional_FK1.Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_nav_prop_reference_optional2_via_DefaultIfEmpty(bool async)
=> AssertQueryScalar(
async,
ss => from l1 in ss.Set<Level1>()
join l2 in ss.Set<Level2>() on l1.Id equals l2.Level1_Optional_Id into groupJoin
from l2 in groupJoin.DefaultIfEmpty()
select l2 == null ? null : (int?)l2.Id);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_nav_prop_reference_optional3(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level2>().Select(e => e.OneToOne_Optional_FK_Inverse2.Name));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_nav_prop_reference_optional1(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<Level1>()
.Where(e => e.OneToOne_Optional_FK1.Name == "L2 05" || e.OneToOne_Optional_FK1.Name == "L2 07")
.Select(e => e.Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_nav_prop_reference_optional1_via_DefaultIfEmpty(bool async)
=> AssertQueryScalar(
async,
ss => from l1 in ss.Set<Level1>()
join l2Left in ss.Set<Level2>() on l1.Id equals l2Left.Level1_Optional_Id into groupJoinLeft
from l2Left in groupJoinLeft.DefaultIfEmpty()
join l2Right in ss.Set<Level2>() on l1.Id equals l2Right.Level1_Optional_Id into groupJoinRight
from l2Right in groupJoinRight.DefaultIfEmpty()
where (l2Left == null ? null : l2Left.Name) == "L2 05" || (l2Right == null ? null : l2Right.Name) == "L2 07"
select l1.Id);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_nav_prop_reference_optional2(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<Level1>()
.Where(e => e.OneToOne_Optional_FK1.Name == "L2 05" || e.OneToOne_Optional_FK1.Name != "L2 42")
.Select(e => e.Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_nav_prop_reference_optional2_via_DefaultIfEmpty(bool async)
=> AssertQueryScalar(
async,
ss => from l1 in ss.Set<Level1>()
join l2Left in ss.Set<Level2>() on l1.Id equals l2Left.Level1_Optional_Id into groupJoinLeft
from l2Left in groupJoinLeft.DefaultIfEmpty()
join l2Right in ss.Set<Level2>() on l1.Id equals l2Right.Level1_Optional_Id into groupJoinRight
from l2Right in groupJoinRight.DefaultIfEmpty()
where (l2Left == null ? null : l2Left.Name) == "L2 05" || (l2Right == null ? null : l2Right.Name) != "L2 42"
select l1.Id);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_multiple_nav_prop_reference_optional(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<Level1>().Select(e => (int?)e.OneToOne_Optional_FK1.OneToOne_Optional_FK2.Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_multiple_nav_prop_reference_optional_member_compared_to_value(bool async)
=> AssertQuery(
async,
ss =>
from l1 in ss.Set<Level1>()
where l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2.Name != "L3 05"
select l1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_multiple_nav_prop_reference_optional_member_compared_to_null(bool async)
=> AssertQuery(
async,
ss =>
from l1 in ss.Set<Level1>()
where l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2.Name != null
select l1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_multiple_nav_prop_reference_optional_compared_to_null1(bool async)
=> AssertQuery(
async,
ss =>
from l1 in ss.Set<Level1>()
where l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2 == null
select l1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_multiple_nav_prop_reference_optional_compared_to_null2(bool async)
=> AssertQuery(
async,
ss =>
from l3 in ss.Set<Level3>()
where l3.OneToOne_Optional_FK_Inverse3.OneToOne_Optional_FK_Inverse2 == null
select l3);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_multiple_nav_prop_reference_optional_compared_to_null3(bool async)
=> AssertQuery(
async,
ss =>
from l1 in ss.Set<Level1>()
where null != l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2
select l1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_multiple_nav_prop_reference_optional_compared_to_null4(bool async)
=> AssertQuery(
async,
ss =>
from l3 in ss.Set<Level3>()
where null != l3.OneToOne_Optional_FK_Inverse3.OneToOne_Optional_FK_Inverse2
select l3);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_multiple_nav_prop_reference_optional_compared_to_null5(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Where(e => e.OneToOne_Optional_FK1.OneToOne_Required_FK2.OneToOne_Required_FK3 == null));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_multiple_nav_prop_reference_required(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<Level1>().Select(e => (int?)e.OneToOne_Required_FK1.OneToOne_Required_FK2.Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_multiple_nav_prop_reference_required2(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<Level3>().Select(e => e.OneToOne_Required_FK_Inverse3.OneToOne_Required_FK_Inverse2.Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_multiple_nav_prop_optional_required(bool async)
=> AssertQueryScalar(
async,
ss => from l1 in ss.Set<Level1>()
select (int?)l1.OneToOne_Optional_FK1.OneToOne_Required_FK2.Id);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_multiple_nav_prop_optional_required(bool async)
=> AssertQuery(
async,
ss =>
from l1 in ss.Set<Level1>()
where l1.OneToOne_Optional_FK1.OneToOne_Required_FK2.Name != "L3 05"
select l1);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task SelectMany_navigation_comparison1(bool async)
=> AssertQuery(
async,
ss =>
from l11 in ss.Set<Level1>()
from l12 in ss.Set<Level1>()
where l11 == l12
select new { Id1 = l11.Id, Id2 = l12.Id },
ss =>
from l11 in ss.Set<Level1>()
from l12 in ss.Set<Level1>()
where l11.Id == l12.Id
select new { Id1 = l11.Id, Id2 = l12.Id },
e => (e.Id1, e.Id2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task SelectMany_navigation_comparison2(bool async)
=> AssertQuery(
async,
ss =>
from l1 in ss.Set<Level1>()
from l2 in ss.Set<Level2>()
where l1 == l2.OneToOne_Optional_FK_Inverse2
select new { Id1 = l1.Id, Id2 = l2.Id },
ss =>
from l1 in ss.Set<Level1>()
from l2 in ss.Set<Level2>()
where l1.Id == l2.OneToOne_Optional_FK_Inverse2.Id
select new { Id1 = l1.Id, Id2 = l2.Id },
e => (e.Id1, e.Id2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task SelectMany_navigation_comparison3(bool async)
=> AssertQuery(
async,
ss =>
from l1 in ss.Set<Level1>()
from l2 in ss.Set<Level2>()
where l1.OneToOne_Optional_FK1 == l2
select new { Id1 = l1.Id, Id2 = l2.Id },
ss =>
from l1 in ss.Set<Level1>()
from l2 in ss.Set<Level2>()
where l1.OneToOne_Optional_FK1.Id == l2.Id
select new { Id1 = l1.Id, Id2 = l2.Id },
e => (e.Id1, e.Id2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_complex_predicate_with_with_nav_prop_and_OrElse1(bool async)
=> AssertQuery(
async,
ss =>
from l1 in ss.Set<Level1>()
from l2 in ss.Set<Level2>()
where l1.OneToOne_Optional_FK1.Name == "L2 01" || l2.OneToOne_Required_FK_Inverse2.Name != "Bar"
select new { Id1 = (int?)l1.Id, Id2 = (int?)l2.Id },
e => (e.Id1, e.Id2));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_complex_predicate_with_with_nav_prop_and_OrElse2(bool async)
=> AssertQueryScalar(
async,
ss => from l1 in ss.Set<Level1>()
where l1.OneToOne_Optional_FK1.OneToOne_Required_FK2.Name == "L3 05" || l1.OneToOne_Optional_FK1.Name != "L2 05"
select l1.Id);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_complex_predicate_with_with_nav_prop_and_OrElse3(bool async)
=> AssertQueryScalar(
async,
ss => from l1 in ss.Set<Level1>()
where l1.OneToOne_Optional_FK1.Name != "L2 05" || l1.OneToOne_Required_FK1.OneToOne_Optional_FK2.Name == "L3 05"
select l1.Id);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Where_complex_predicate_with_with_nav_prop_and_OrElse4(bool async)
=> AssertQueryScalar(
async,
ss => from l3 in ss.Set<Level3>()
where l3.OneToOne_Optional_FK_Inverse3.Name != "L2 05"
|| l3.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK_Inverse2.Name == "L1 05"
select l3.Id);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Complex_navigations_with_predicate_projected_into_anonymous_type(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>()
.Where(
e => e.OneToOne_Required_FK1.OneToOne_Required_FK2 == e.OneToOne_Required_FK1.OneToOne_Optional_FK2
&& e.OneToOne_Required_FK1.OneToOne_Optional_FK2.Id != 7)
.Select(e => new { e.Name, Id = (int?)e.OneToOne_Required_FK1.OneToOne_Optional_FK2.Id }),
elementSorter: e => (e.Name, e.Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Complex_navigations_with_predicate_projected_into_anonymous_type2(bool async)
=> AssertQuery(
async,
ss => from e in ss.Set<Level3>()
where e.OneToOne_Required_FK_Inverse3.OneToOne_Required_FK_Inverse2
!= e.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK_Inverse2
&& e.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK_Inverse2.Id != 7
select new { e.Name, Id = (int?)e.OneToOne_Required_FK_Inverse3.OneToOne_Optional_FK_Inverse2.Id },
e => (e.Name, e.Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Optional_navigation_projected_into_DTO(bool async)
=> AssertQuery(
async,
ss => ss.Set<Level1>().Select(
e => new MyOuterDto
{
Id = e.Id,
Name = e.Name,
Inner = e.OneToOne_Optional_FK1 != null
? new MyInnerDto { Id = e.OneToOne_Optional_FK1.Id, Name = e.OneToOne_Optional_FK1.Name }
: null
}),
elementSorter: e => e.Id,
elementAsserter: (e, a) =>
{
Assert.Equal(e.Id, a.Id);
Assert.Equal(e.Name, a.Name);
Assert.Equal(e.Inner?.Id, a.Inner?.Id);
Assert.Equal(e.Inner?.Name, a.Inner?.Name);
});
public class MyOuterDto
{
public int Id { get; set; }
public string Name { get; set; }
public MyInnerDto Inner { get; set; }
}
public class MyInnerDto
{
public int? Id { get; set; }
public string Name { get; set; }
}
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task OrderBy_nav_prop_reference_optional(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<Level1>().OrderBy(e => e.OneToOne_Optional_FK1.Name).ThenBy(e => e.Id).Select(e => e.Id),
assertOrder: true);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task OrderBy_nav_prop_reference_optional_via_DefaultIfEmpty(bool async)
=> AssertQueryScalar(
async,
ss => from l1 in ss.Set<Level1>()
join l2 in ss.Set<Level2>() on l1.Id equals l2.Level1_Optional_Id into groupJoin
from l2 in groupJoin.DefaultIfEmpty()
orderby l2 == null ? null : l2.Name, l1.Id
select l1.Id,
assertOrder: true);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Result_operator_nav_prop_reference_optional_Sum(bool async)
=> AssertSum(
async,
ss => ss.Set<Level1>(),
ss => ss.Set<Level1>(),
actualSelector: e => e.OneToOne_Optional_FK1.Level1_Required_Id,
expectedSelector: e => e.OneToOne_Optional_FK1.MaybeScalar(x => x.Level1_Required_Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Result_operator_nav_prop_reference_optional_Min(bool async)
=> AssertMin(
async,
ss => ss.Set<Level1>(),
ss => ss.Set<Level1>(),
actualSelector: e => e.OneToOne_Optional_FK1.Level1_Required_Id,
expectedSelector: e => e.OneToOne_Optional_FK1.MaybeScalar(x => x.Level1_Required_Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Result_operator_nav_prop_reference_optional_Max(bool async)
=> AssertMax(
async,
ss => ss.Set<Level1>(),
ss => ss.Set<Level1>(),
actualSelector: e => e.OneToOne_Optional_FK1.Level1_Required_Id,
expectedSelector: e => e.OneToOne_Optional_FK1.MaybeScalar(x => x.Level1_Required_Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Result_operator_nav_prop_reference_optional_Average(bool async)
=> AssertAverage(
async,
ss => ss.Set<Level1>(),
ss => ss.Set<Level1>(),
actualSelector: e => e.OneToOne_Optional_FK1.Level1_Required_Id,
expectedSelector: e => e.OneToOne_Optional_FK1.MaybeScalar(x => x.Level1_Required_Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Result_operator_nav_prop_reference_optional_Average_with_identity_selector(bool async)
=> AssertAverage(
async,
ss => ss.Set<Level1>().Select(e => (int?)e.OneToOne_Optional_FK1.Level1_Required_Id),
selector: e => e);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Result_operator_nav_prop_reference_optional_Average_without_selector(bool async)
=> AssertAverage(
async,
ss => ss.Set<Level1>().Select(e => (int?)e.OneToOne_Optional_FK1.Level1_Required_Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Result_operator_nav_prop_reference_optional_via_DefaultIfEmpty(bool async)
=> AssertSum(
async,
ss => from l1 in ss.Set<Level1>()
join l2 in ss.Set<Level2>() on l1.Id equals l2.Level1_Optional_Id into groupJoin
from l2 in groupJoin.DefaultIfEmpty()
select l2,
selector: e => e == null ? 0 : e.Level1_Required_Id);
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Include_with_optional_navigation(bool async)
=> AssertQuery(
async,
ss => from l1 in ss.Set<Level1>().Include(e => e.OneToOne_Optional_FK1)
where l1.OneToOne_Optional_FK1.Name != "L2 05"
select l1,
elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude<Level1>(l1 => l1.OneToOne_Optional_FK1)));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_flattening_bug_4539(bool async)
=> AssertQuery(
async,
ss =>
from l1 in ss.Set<Level1>()
join l1_Optional in ss.Set<Level2>() on l1.Id equals l1_Optional.Level1_Optional_Id into grouping
from l1_Optional in grouping.DefaultIfEmpty()
from l2 in ss.Set<Level2>()
join l2_Required_Reverse in ss.Set<Level1>() on l2.Level1_Required_Id equals l2_Required_Reverse.Id
select new { l1_Optional, l2_Required_Reverse },
elementSorter: e => (e.l1_Optional?.Id, e.l2_Required_Reverse.Id));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Query_source_materialization_bug_4547(bool async)
=> AssertQueryScalar(
async,
ss => from e3 in ss.Set<Level3>()
join e1 in ss.Set<Level1>()
on
e3.Id
equals
(
from subQuery2 in ss.Set<Level2>()
join subQuery3 in ss.Set<Level3>()