From 56dc5190820460f93667ac47b2b08c6615d10ddc Mon Sep 17 00:00:00 2001 From: maumar Date: Tue, 8 Dec 2020 22:51:47 -0800 Subject: [PATCH] Fix to #21049 - Test: Consider adding Include tests with smaller datasets Fixes #21049 --- .../NorthwindFunctionsQueryCosmosTest.cs | 2 +- .../Query/ComplexNavigationsQueryTestBase.cs | 88 +++++++++++- .../Query/NorthwindFunctionsQueryTestBase.cs | 58 +++++--- .../Query/NorthwindIncludeQueryTestBase.cs | 135 ++++++++++-------- .../Query/NorthwindJoinQueryTestBase.cs | 60 ++++---- .../ComplexNavigationsQuerySqlServerTest.cs | 63 ++++++++ .../NorthwindFunctionsQuerySqlServerTest.cs | 26 ++-- .../NorthwindIncludeQuerySqlServerTest.cs | 43 ++++-- .../Query/NorthwindJoinQuerySqlServerTest.cs | 33 +++-- ...NorthwindSplitIncludeQuerySqlServerTest.cs | 68 +++++++-- .../NorthwindFunctionsQuerySqliteTest.cs | 10 +- 11 files changed, 416 insertions(+), 170 deletions(-) diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs index 6c86e0b9347..e3770d9c77b 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs @@ -330,7 +330,7 @@ public override async Task Where_math_abs_uncorrelated(bool async) AssertSql( @"SELECT c FROM root c -WHERE ((c[""Discriminator""] = ""OrderDetail"") AND (10 < c[""ProductID""]))"); +WHERE (((c[""Discriminator""] = ""OrderDetail"") AND (c[""UnitPrice""] < 7.0)) AND (10 < c[""ProductID""]))"); } [ConditionalTheory(Skip = "Issue #17246")] diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs index 380c20bfdca..197d8e5cc9c 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs @@ -738,6 +738,92 @@ public virtual Task Multiple_complex_includes_self_ref(bool async) elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Include_reference_and_collection_order_by(bool async) + { + var expectedIncludes = new IExpectedInclude[] + { + new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), + }; + + return AssertQuery( + async, + ss => ss.Set() + .Include(e => e.OneToOne_Optional_FK1.OneToMany_Optional2) + .OrderBy(e => e.Name), + assertOrder: true, + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Include_reference_ThenInclude_collection_order_by(bool async) + { + var expectedIncludes = new IExpectedInclude[] + { + new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), + new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), + }; + + return AssertQuery( + async, + ss => ss.Set() + .Include(e => e.OneToOne_Optional_FK1) + .ThenInclude(e => e.OneToMany_Optional2) + .OrderBy(e => e.Name), + assertOrder: true, + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Include_collection_then_reference(bool async) + { + var expectedIncludes = new IExpectedInclude[] + { + new ExpectedInclude(l1 => l1.OneToMany_Optional1), + new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToMany_Optional1"), + }; + + return AssertQuery( + async, + ss => ss.Set() + .Include(e => e.OneToMany_Optional1) + .ThenInclude(e => e.OneToOne_Optional_FK2), + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Include_reference_and_project_into_anonymous_type(bool async) + { + return AssertQuery( + async, + ss => ss.Set().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(ee => ee.OneToOne_Optional_FK1)); + AssertEqual(e.Id, a.Id); + }); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Include_collection_with_conditional_order_by(bool async) + { + return AssertQuery( + async, + ss => ss.Set() + .Include(e => e.OneToMany_Optional1) + .OrderBy(e => e.Name.EndsWith("03") ? 1 : 2) + .Select(e => e), + elementSorter: e => e.Id, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(ee => ee.OneToMany_Optional1))); + } + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_complex_include_select(bool async) @@ -753,10 +839,8 @@ public virtual Task Multiple_complex_include_select(bool async) return AssertQuery( async, ss => ss.Set() - .Select(e => e) .Include(e => e.OneToOne_Optional_FK1) .ThenInclude(e => e.OneToMany_Optional2) - .Select(e => e) .Include(e => e.OneToMany_Optional1) .ThenInclude(e => e.OneToOne_Optional_FK2), elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); diff --git a/test/EFCore.Specification.Tests/Query/NorthwindFunctionsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindFunctionsQueryTestBase.cs index 60ed1b10f11..674a88f3600 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindFunctionsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindFunctionsQueryTestBase.cs @@ -749,8 +749,9 @@ public virtual Task Where_math_abs1(bool async) { return AssertQuery( async, - ss => ss.Set().Where(od => Math.Abs(od.ProductID) > 10), - entryCount: 1939); + ss => ss.Set() + .Where(od => Math.Abs(od.ProductID) > 10), + entryCount: 67); } [ConditionalTheory] @@ -759,8 +760,10 @@ public virtual Task Where_math_abs2(bool async) { return AssertQuery( async, - ss => ss.Set().Where(od => Math.Abs(od.Quantity) > 10), - entryCount: 1547); + ss => ss.Set() + .Where(od => od.UnitPrice < 7) + .Where(od => Math.Abs(od.Quantity) > 10), + entryCount: 102); } [ConditionalTheory] @@ -769,8 +772,10 @@ public virtual Task Where_math_abs3(bool async) { return AssertQuery( async, - ss => ss.Set().Where(od => Math.Abs(od.UnitPrice) > 10), - entryCount: 1677); + ss => ss.Set() + .Where(od => od.Quantity < 5) + .Where(od => Math.Abs(od.UnitPrice) > 10), + entryCount: 137); } [ConditionalTheory] @@ -779,8 +784,10 @@ public virtual Task Where_math_abs_uncorrelated(bool async) { return AssertQuery( async, - ss => ss.Set().Where(od => Math.Abs(-10) < od.ProductID), - entryCount: 1939); + ss => ss.Set() + .Where(od => od.UnitPrice < 7) + .Where(od => Math.Abs(-10) < od.ProductID), + entryCount: 154); } [ConditionalTheory] @@ -789,8 +796,10 @@ public virtual Task Where_math_ceiling1(bool async) { return AssertQuery( async, - ss => ss.Set().Where(od => Math.Ceiling(od.Discount) > 0), - entryCount: 838); + ss => ss.Set() + .Where(od => od.UnitPrice < 7) + .Where(od => Math.Ceiling(od.Discount) > 0), + entryCount: 51); } [ConditionalTheory] @@ -799,8 +808,10 @@ public virtual Task Where_math_ceiling2(bool async) { return AssertQuery( async, - ss => ss.Set().Where(od => Math.Ceiling(od.UnitPrice) > 10), - entryCount: 1677); + ss => ss.Set() + .Where(od => od.Quantity < 5) + .Where(od => Math.Ceiling(od.UnitPrice) > 10), + entryCount: 137); } [ConditionalTheory] @@ -809,8 +820,10 @@ public virtual Task Where_math_floor(bool async) { return AssertQuery( async, - ss => ss.Set().Where(od => Math.Floor(od.UnitPrice) > 10), - entryCount: 1658); + ss => ss.Set() + .Where(od => od.Quantity < 5) + .Where(od => Math.Floor(od.UnitPrice) > 10), + entryCount: 137); } [ConditionalTheory] @@ -829,8 +842,10 @@ public virtual Task Where_math_round(bool async) { return AssertQuery( async, - ss => ss.Set().Where(od => Math.Round(od.UnitPrice) > 10), - entryCount: 1662); + ss => ss.Set() + .Where(od => od.Quantity < 5) + .Where(od => Math.Round(od.UnitPrice) > 10), + entryCount: 137); } [ConditionalTheory] @@ -873,8 +888,10 @@ public virtual Task Where_math_truncate(bool async) { return AssertQuery( async, - ss => ss.Set().Where(od => Math.Truncate(od.UnitPrice) > 10), - entryCount: 1658); + ss => ss.Set() + .Where(od => od.Quantity < 5) + .Where(od => Math.Truncate(od.UnitPrice) > 10), + entryCount: 137); } [ConditionalTheory] @@ -1034,8 +1051,9 @@ public virtual Task Where_guid_newguid(bool async) { return AssertQuery( async, - ss => ss.Set().Where(od => Guid.NewGuid() != default), - entryCount: 2155); + ss => ss.Set() + .Where(od => Guid.NewGuid() != default), + entryCount: 91); } [ConditionalTheory] diff --git a/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs index 09fed498ea5..9cdc9e3b396 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs @@ -32,12 +32,12 @@ public virtual Task Include_reference_and_collection_order_by(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.Customer.Orders).OrderBy(o => o.OrderID), + ss => ss.Set().Where(o => o.CustomerID.StartsWith("F")).Include(o => o.Customer.Orders).OrderBy(o => o.OrderID), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(o => o.Customer), new ExpectedInclude(c => c.Orders, "Customer")), assertOrder: true, - entryCount: 919); + entryCount: 70); } [ConditionalTheory] @@ -46,12 +46,12 @@ public virtual async Task Include_references_then_include_collection(bool async) { await AssertQuery( async, - ss => ss.Set().Include(o => o.Customer).ThenInclude(c => c.Orders), + ss => ss.Set().Where(o => o.CustomerID.StartsWith("F")).Include(o => o.Customer).ThenInclude(c => c.Orders), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(o => o.Customer), new ExpectedInclude(c => c.Orders, "Customer")), - entryCount: 919); + entryCount: 70); } [ConditionalTheory] @@ -150,9 +150,9 @@ public virtual Task Include_collection(bool async) { return AssertQuery( async, - ss => ss.Set().Include(c => c.Orders), + ss => ss.Set().Where(c => c.CustomerID.StartsWith("F")).Include(c => c.Orders), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(c => c.Orders)), - entryCount: 921); + entryCount: 71); } [ConditionalTheory] @@ -161,12 +161,12 @@ public virtual Task Include_collection_then_reference(bool async) { return AssertQuery( async, - ss => ss.Set().Include(p => p.OrderDetails).ThenInclude(od => od.Order), + ss => ss.Set().Where(p => p.ProductID % 17 == 5).Include(p => p.OrderDetails).ThenInclude(od => od.Order), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(p => p.OrderDetails), new ExpectedInclude(od => od.Order, "OrderDetails")), - entryCount: 3062); + entryCount: 237); } [ConditionalTheory] @@ -229,12 +229,12 @@ public virtual Task Include_list(bool async) { return AssertQuery( async, - ss => ss.Set().Include(p => p.OrderDetails).ThenInclude(od => od.Order), + ss => ss.Set().Where(p => p.ProductID % 17 == 5 && p.UnitPrice < 20).Include(p => p.OrderDetails).ThenInclude(od => od.Order), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(p => p.OrderDetails), new ExpectedInclude(od => od.Order, "OrderDetails")), - entryCount: 3062); + entryCount: 89); } [ConditionalTheory] @@ -243,9 +243,9 @@ public virtual Task Include_collection_alias_generation(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.OrderDetails), + ss => ss.Set().Where(o => o.CustomerID.StartsWith("F")).Include(o => o.OrderDetails), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.OrderDetails)), - entryCount: 2985); + entryCount: 227); } [ConditionalTheory] @@ -254,11 +254,11 @@ public virtual Task Include_collection_and_reference(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.OrderDetails).Include(o => o.Customer), + ss => ss.Set().Where(o => o.CustomerID.StartsWith("F")).Include(o => o.OrderDetails).Include(o => o.Customer), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(o => o.OrderDetails), new ExpectedInclude(o => o.Customer)), - entryCount: 3074); + entryCount: 234); } [ConditionalTheory] @@ -302,10 +302,10 @@ public virtual Task Include_collection_on_additional_from_clause(bool async) return AssertQuery( async, ss => from c1 in ss.Set().OrderBy(c => c.CustomerID).Take(5) - from c2 in ss.Set().Include(c2 => c2.Orders) + from c2 in ss.Set().Where(c2 => c2.CustomerID.StartsWith("F")).Include(c2 => c2.Orders) select c2, elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(c => c.Orders)), - entryCount: 921); + entryCount: 71); } [ConditionalTheory] @@ -472,10 +472,10 @@ public virtual Task Include_collection_order_by_key(bool async) { return AssertQuery( async, - ss => ss.Set().Include(c => c.Orders).OrderBy(c => c.CustomerID), + ss => ss.Set().Where(c => c.CustomerID.StartsWith("F")).Include(c => c.Orders).OrderBy(c => c.CustomerID), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(c => c.Orders)), assertOrder: true, - entryCount: 921); + entryCount: 71); } [ConditionalTheory] @@ -484,10 +484,10 @@ public virtual Task Include_collection_order_by_non_key(bool async) { return AssertQuery( async, - ss => ss.Set().Include(c => c.Orders).OrderBy(c => c.PostalCode), + ss => ss.Set().Where(c => c.CustomerID.StartsWith("F")).Include(c => c.Orders).OrderBy(c => c.PostalCode), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(c => c.Orders)), assertOrder: true, - entryCount: 921); + entryCount: 71); } [ConditionalTheory] @@ -507,9 +507,9 @@ public virtual Task Include_collection_order_by_non_key_with_skip(bool async) { return AssertQuery( async, - ss => ss.Set().Include(c => c.Orders).OrderBy(c => c.ContactTitle).Skip(10), + ss => ss.Set().Where(c => c.CustomerID.StartsWith("F")).Include(c => c.Orders).OrderBy(c => c.ContactTitle).Skip(2), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(c => c.Orders)), - entryCount: 795); + entryCount: 64); } [ConditionalTheory] @@ -760,12 +760,12 @@ public virtual Task Include_multiple_references(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.Order).Include(o => o.Product), + ss => ss.Set().Where(od => od.OrderID % 23 == 13).Include(o => o.Order).Include(o => o.Product), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(od => od.Order), new ExpectedInclude(od => od.Product)), - entryCount: 3062); + entryCount: 183); } [ConditionalTheory] @@ -774,14 +774,14 @@ public virtual Task Include_multiple_references_and_collection_multi_level(bool { return AssertQuery( async, - ss => ss.Set().Include(od => od.Order.Customer.Orders).Include(od => od.Product), + ss => ss.Set().Where(od => od.OrderID % 23 == 13).Include(od => od.Order.Customer.Orders).Include(od => od.Product), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order"), new ExpectedInclude(c => c.Orders, "Order.Customer"), new ExpectedInclude(od => od.Product)), - entryCount: 3151); + entryCount: 516); } [ConditionalTheory] @@ -790,14 +790,14 @@ public virtual Task Include_multiple_references_and_collection_multi_level_rever { return AssertQuery( async, - ss => ss.Set().Include(od => od.Product).Include(od => od.Order.Customer.Orders), + ss => ss.Set().Where(od => od.OrderID % 23 == 13).Include(od => od.Product).Include(od => od.Order.Customer.Orders), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order"), new ExpectedInclude(c => c.Orders, "Order.Customer"), new ExpectedInclude(od => od.Product)), - entryCount: 3151); + entryCount: 516); } [ConditionalTheory] @@ -806,13 +806,13 @@ public virtual Task Include_multiple_references_multi_level(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.Order.Customer).Include(o => o.Product), + ss => ss.Set().Where(od => od.OrderID % 23 == 13).Include(o => o.Order.Customer).Include(o => o.Product), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order"), new ExpectedInclude(od => od.Product)), - entryCount: 3151); + entryCount: 213); } [ConditionalTheory] @@ -821,13 +821,13 @@ public virtual Task Include_multiple_references_multi_level_reverse(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.Product).Include(o => o.Order.Customer), + ss => ss.Set().Where(od => od.OrderID % 23 == 13).Include(o => o.Product).Include(o => o.Order.Customer), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order"), new ExpectedInclude(od => od.Product)), - entryCount: 3151); + entryCount: 213); } [ConditionalTheory] @@ -836,9 +836,9 @@ public virtual Task Include_reference(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.Customer), + ss => ss.Set().Where(o => o.CustomerID.StartsWith("F")).Include(o => o.Customer), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Customer)), - entryCount: 919); + entryCount: 70); } [ConditionalTheory] @@ -847,9 +847,9 @@ public virtual async Task Include_reference_alias_generation(bool async) { await AssertQuery( async, - ss => ss.Set().Include(o => o.Order), + ss => ss.Set().Where(od => od.OrderID % 23 == 13).Include(o => o.Order), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(od => od.Order)), - entryCount: 2985); + entryCount: 131); } [ConditionalTheory] @@ -858,12 +858,12 @@ public virtual Task Include_reference_and_collection(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.Customer).Include(o => o.OrderDetails), + ss => ss.Set().Where(o => o.CustomerID.StartsWith("F")).Include(o => o.Customer).Include(o => o.OrderDetails), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(o => o.Customer), new ExpectedInclude(o => o.OrderDetails)), - entryCount: 3074); + entryCount: 234); } [ConditionalTheory] @@ -923,14 +923,14 @@ public virtual Task Include_reference_when_entity_in_projection(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.Customer).Select(o => new { o, o.CustomerID }), + ss => ss.Set().Where(o => o.CustomerID.StartsWith("F")).Include(o => o.Customer).Select(o => new { o, o.CustomerID }), elementSorter: e => e.o.OrderID, elementAsserter: (e, a) => { AssertInclude(e.o, a.o, new ExpectedInclude(o => o.Customer)); AssertEqual(e.CustomerID, a.CustomerID); }, - entryCount: 919); + entryCount: 70); } [ConditionalTheory] @@ -961,13 +961,13 @@ public virtual Task Include_references_and_collection_multi_level(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.Order.Customer.Orders), + ss => ss.Set().Where(od => od.OrderID % 23 == 13 && od.UnitPrice < 10).Include(o => o.Order.Customer.Orders), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order"), new ExpectedInclude(c => c.Orders, "Order.Customer")), - entryCount: 3074); + entryCount: 227); } [ConditionalTheory] @@ -976,12 +976,12 @@ public virtual Task Include_collection_then_include_collection(bool async) { return AssertQuery( async, - ss => ss.Set().Include(c => c.Orders).ThenInclude(o => o.OrderDetails), + ss => ss.Set().Where(c => c.CustomerID.StartsWith("F")).Include(c => c.Orders).ThenInclude(o => o.OrderDetails), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(c => c.Orders), new ExpectedInclude(o => o.OrderDetails, "Orders")), - entryCount: 3076); + entryCount: 235); } [ConditionalTheory] @@ -990,13 +990,13 @@ public virtual Task Include_collection_then_include_collection_then_include_refe { return AssertQuery( async, - ss => ss.Set().Include(c => c.Orders).ThenInclude(o => o.OrderDetails).ThenInclude(od => od.Product), + ss => ss.Set().Where(c => c.CustomerID.StartsWith("F")).Include(c => c.Orders).ThenInclude(o => o.OrderDetails).ThenInclude(od => od.Product), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(c => c.Orders), new ExpectedInclude(o => o.OrderDetails, "Orders"), new ExpectedInclude(od => od.Product, "Orders.OrderDetails")), - entryCount: 3153); + entryCount: 293); } [ConditionalTheory] @@ -1035,12 +1035,12 @@ public virtual Task Include_references_multi_level(bool async) { return AssertQuery( async, - ss => ss.Set().Include(o => o.Order.Customer), + ss => ss.Set().Where(od => od.OrderID % 23 == 13).Include(o => o.Order.Customer), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order")), - entryCount: 3074); + entryCount: 161); } [ConditionalTheory] @@ -1065,6 +1065,7 @@ public virtual Task Include_multiple_references_then_include_collection_multi_le return AssertQuery( async, ss => ss.Set() + .Where(od => od.OrderID % 23 == 13) .Include(od => od.Order).ThenInclude(o => o.Customer).ThenInclude(c => c.Orders) .Include(od => od.Product), elementAsserter: (e, a) => AssertInclude( @@ -1073,7 +1074,7 @@ public virtual Task Include_multiple_references_then_include_collection_multi_le new ExpectedInclude(o => o.Customer, "Order"), new ExpectedInclude(c => c.Orders, "Order.Customer"), new ExpectedInclude(od => od.Product)), - entryCount: 3151); + entryCount: 516); } [ConditionalTheory] @@ -1083,6 +1084,7 @@ public virtual Task Include_multiple_references_then_include_collection_multi_le return AssertQuery( async, ss => ss.Set() + .Where(od => od.OrderID % 23 == 13) .Include(od => od.Product) .Include(od => od.Order).ThenInclude(o => o.Customer).ThenInclude(c => c.Orders), elementAsserter: (e, a) => AssertInclude( @@ -1091,7 +1093,7 @@ public virtual Task Include_multiple_references_then_include_collection_multi_le new ExpectedInclude(o => o.Customer, "Order"), new ExpectedInclude(c => c.Orders, "Order.Customer"), new ExpectedInclude(od => od.Product)), - entryCount: 3151); + entryCount: 516); } [ConditionalTheory] @@ -1101,6 +1103,7 @@ public virtual Task Include_multiple_references_then_include_multi_level(bool as return AssertQuery( async, ss => ss.Set() + .Where(od => od.OrderID % 23 == 13) .Include(od => od.Order).ThenInclude(o => o.Customer) .Include(od => od.Product), elementAsserter: (e, a) => AssertInclude( @@ -1108,7 +1111,7 @@ public virtual Task Include_multiple_references_then_include_multi_level(bool as new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order"), new ExpectedInclude(od => od.Product)), - entryCount: 3151); + entryCount: 213); } [ConditionalTheory] @@ -1118,6 +1121,7 @@ public virtual Task Include_multiple_references_then_include_multi_level_reverse return AssertQuery( async, ss => ss.Set() + .Where(od => od.OrderID % 23 == 13) .Include(od => od.Product) .Include(od => od.Order).ThenInclude(o => o.Customer), elementAsserter: (e, a) => AssertInclude( @@ -1125,7 +1129,7 @@ public virtual Task Include_multiple_references_then_include_multi_level_reverse new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order"), new ExpectedInclude(od => od.Product)), - entryCount: 3151); + entryCount: 213); } [ConditionalTheory] @@ -1135,13 +1139,16 @@ public virtual Task Include_references_then_include_collection_multi_level(bool return AssertQuery( async, ss => ss.Set() - .Include(od => od.Order).ThenInclude(o => o.Customer).ThenInclude(c => c.Orders), + .Where(od => od.ProductID % 23 == 17 && od.Quantity < 10) + .Include(od => od.Order) + .ThenInclude(o => o.Customer) + .ThenInclude(c => c.Orders), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order"), new ExpectedInclude(c => c.Orders, "Order.Customer")), - entryCount: 3074); + entryCount: 229); } [ConditionalTheory] @@ -1151,7 +1158,9 @@ public virtual Task Include_references_then_include_collection_multi_level_predi return AssertQuery( async, ss => ss.Set() - .Include(od => od.Order).ThenInclude(o => o.Customer).ThenInclude(c => c.Orders) + .Include(od => od.Order) + .ThenInclude(o => o.Customer) + .ThenInclude(c => c.Orders) .Where(od => od.OrderID == 10248), elementAsserter: (e, a) => AssertInclude( e, a, @@ -1168,12 +1177,14 @@ public virtual Task Include_references_then_include_multi_level(bool async) return AssertQuery( async, ss => ss.Set() - .Include(od => od.Order).ThenInclude(o => o.Customer), + .Where(od => od.OrderID % 23 == 13) + .Include(od => od.Order) + .ThenInclude(o => o.Customer), elementAsserter: (e, a) => AssertInclude( e, a, new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order")), - entryCount: 3074); + entryCount: 161); } [ConditionalTheory] @@ -1240,10 +1251,14 @@ public virtual Task Include_collection_with_conditional_order_by(bool async) { return AssertQuery( async, - ss => ss.Set().Include(c => c.Orders).OrderBy(c => c.CustomerID.StartsWith("S") ? 1 : 2), + ss => ss.Set() + .Where(c => c.CustomerID.StartsWith("F")) + .Include(c => c.Orders) + .OrderBy(c => c.CustomerID.StartsWith("S") ? 1 : 2) + .Select(c => c), elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(c => c.Orders)), - assertOrder: true, - entryCount: 921); + elementSorter: e => e.CustomerID, + entryCount: 71); } [ConditionalTheory] diff --git a/test/EFCore.Specification.Tests/Query/NorthwindJoinQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindJoinQueryTestBase.cs index d39b3d6dc70..27590388b8f 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindJoinQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindJoinQueryTestBase.cs @@ -46,11 +46,11 @@ public virtual Task Join_customers_orders_entities(bool async) return AssertQuery( async, ss => - from c in ss.Set() + from c in ss.Set().Where(c => c.CustomerID.StartsWith("F")) join o in ss.Set() on c.CustomerID equals o.CustomerID select new { c, o }, e => (e.c.CustomerID, e.o.OrderID), - entryCount: 919); + entryCount: 70); } [ConditionalTheory] @@ -73,7 +73,7 @@ public virtual Task Join_select_many(bool async) { return AssertQuery( async, - ss => from c in ss.Set() + ss => from c in ss.Set().Where(c => c.CustomerID.StartsWith("F")) join o in ss.Set() on c.CustomerID equals o.CustomerID from e in ss.Set() select new @@ -83,7 +83,7 @@ from e in ss.Set() e }, e => (e.c.CustomerID, e.o.OrderID, e.e.EmployeeID), - entryCount: 928); + entryCount: 79); } [ConditionalTheory(Skip = "Issue #17328")] @@ -236,12 +236,12 @@ public virtual Task Join_composite_key(bool async) return AssertQuery( async, ss => - from c in ss.Set() + from c in ss.Set().Where(c => c.CustomerID.StartsWith("F")) join o in ss.Set() on new { a = c.CustomerID, b = c.CustomerID } equals new { a = o.CustomerID, b = o.CustomerID } select new { c, o }, e => e.o.OrderID, - entryCount: 919); + entryCount: 70); } [ConditionalTheory] @@ -334,10 +334,10 @@ public virtual Task Join_same_collection_force_alias_uniquefication(bool async) return AssertQuery( async, ss => - ss.Set().Join( + ss.Set().Where(o => o.CustomerID.StartsWith("F")).Join( ss.Set(), o => o.CustomerID, i => i.CustomerID, (_, o) => new { _, o }), e => (e._.OrderID, e.o.OrderID), - entryCount: 830); + entryCount: 63); } [ConditionalTheory] @@ -351,9 +351,7 @@ public virtual Task GroupJoin_customers_employees_shadow(bool async) join e in ss.Set() on c.City equals e.City into employees select employees) .SelectMany(emps => emps) - .Select( - e => - new { Title = EF.Property(e, "Title"), Id = e.EmployeeID }), + .Select(e => new { Title = EF.Property(e, "Title"), Id = e.EmployeeID }), e => e.Id); } @@ -368,9 +366,7 @@ public virtual Task GroupJoin_customers_employees_subquery_shadow(bool async) join e in ss.Set().OrderBy(e => e.City) on c.City equals e.City into employees select employees) .SelectMany(emps => emps) - .Select( - e => - new { Title = EF.Property(e, "Title"), Id = e.EmployeeID }), + .Select(e => new { Title = EF.Property(e, "Title"), Id = e.EmployeeID }), e => e.Id); } @@ -385,9 +381,7 @@ public virtual Task GroupJoin_customers_employees_subquery_shadow_take(bool asyn join e in ss.Set().OrderBy(e => e.City).Take(5) on c.City equals e.City into employees select employees) .SelectMany(emps => emps) - .Select( - e => - new { Title = EF.Property(e, "Title"), Id = e.EmployeeID }), + .Select(e => new { Title = EF.Property(e, "Title"), Id = e.EmployeeID }), e => e.Id); } @@ -398,11 +392,11 @@ public virtual Task GroupJoin_simple(bool async) return AssertQuery( async, ss => - from c in ss.Set() + from c in ss.Set().Where(c => c.CustomerID.StartsWith("F")) join o in ss.Set() on c.CustomerID equals o.CustomerID into orders from o in orders select o, - entryCount: 830); + entryCount: 63); } [ConditionalTheory] @@ -440,11 +434,11 @@ public virtual Task GroupJoin_simple_ordering(bool async) return AssertQuery( async, ss => - from c in ss.Set().OrderBy(c => c.City) + from c in ss.Set().Where(c => c.CustomerID.StartsWith("F")).OrderBy(c => c.City) join o in ss.Set() on c.CustomerID equals o.CustomerID into orders from o in orders select o, - entryCount: 830); + entryCount: 63); } [ConditionalTheory] @@ -468,12 +462,12 @@ public virtual Task GroupJoin_projection(bool async) return AssertQuery( async, ss => - from c in ss.Set() + from c in ss.Set().Where(c => c.CustomerID.StartsWith("F")) join o in ss.Set() on c.CustomerID equals o.CustomerID into orders from o in orders select new { c, o }, e => (e.c.CustomerID, e.o.OrderID), - entryCount: 919); + entryCount: 70); } [ConditionalTheory] @@ -503,12 +497,12 @@ public virtual Task GroupJoin_DefaultIfEmpty(bool async) return AssertQuery( async, ss => - from c in ss.Set() + from c in ss.Set().Where(c => c.CustomerID.StartsWith("F")) join o in ss.Set() on c.CustomerID equals o.CustomerID into orders from o in orders.DefaultIfEmpty() select new { c, o }, e => (e.c.CustomerID, e.o?.OrderID), - entryCount: 921); + entryCount: 71); } [ConditionalTheory] @@ -518,7 +512,7 @@ public virtual Task GroupJoin_DefaultIfEmpty_multiple(bool async) return AssertQuery( async, ss => - from c in ss.Set() + from c in ss.Set().Where(c => c.CustomerID.StartsWith("F")) join o1 in ss.Set() on c.CustomerID equals o1.CustomerID into orders1 from o1 in orders1.DefaultIfEmpty() join o2 in ss.Set() on c.CustomerID equals o2.CustomerID into orders2 @@ -530,7 +524,7 @@ from o2 in orders2.DefaultIfEmpty() o2 }, e => (e.c.CustomerID, e.o1?.OrderID, e.o2?.OrderID), - entryCount: 921); + entryCount: 71); } [ConditionalTheory] @@ -541,11 +535,11 @@ public virtual Task GroupJoin_DefaultIfEmpty2(bool async) async, ss => from e in ss.Set() - join o in ss.Set() on e.EmployeeID equals o.EmployeeID into orders + join o in ss.Set().Where(o => o.CustomerID.StartsWith("F")) on e.EmployeeID equals o.EmployeeID into orders from o in orders.DefaultIfEmpty() select new { e, o }, e => (e.e.EmployeeID, e.o?.OrderID), - entryCount: 839); + entryCount: 72); } [ConditionalTheory] @@ -676,12 +670,12 @@ public virtual Task GroupJoin_SelectMany_subquery_with_filter_and_DefaultIfEmpty return AssertQuery( async, ss => - from c in ss.Set() + from c in ss.Set().Where(c => c.CustomerID.StartsWith("F")) join o in ss.Set() on c.CustomerID equals o.CustomerID into lo from o in lo.Where(x => x.OrderID > 5).DefaultIfEmpty() select new { c.ContactName, o }, e => (e.ContactName, e.o?.OrderID), - entryCount: 830); + entryCount: 63); } [ConditionalTheory(Skip = "Issue #19015")] @@ -691,12 +685,12 @@ public virtual Task GroupJoin_SelectMany_subquery_with_filter_orderby_and_Defaul return AssertQuery( async, ss => - from c in ss.Set() + from c in ss.Set().Where(c => c.CustomerID.StartsWith("F")) join o in ss.Set() on c.CustomerID equals o.CustomerID into lo from o in lo.Where(x => x.OrderID > 5).OrderBy(x => x.OrderDate).DefaultIfEmpty() select new { c.ContactName, o }, e => (e.ContactName, e.o?.OrderID), - entryCount: 830); + entryCount: 23); } [ConditionalTheory] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs index 54c46d13287..4512389fb2e 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs @@ -571,6 +571,69 @@ FROM [LevelOne] AS [l2] ORDER BY [l].[Id], [l0].[Id], [l1].[Id], [t].[Id], [t].[Id0]"); } + public override async Task Include_reference_and_collection_order_by(bool async) + { + await base.Include_reference_and_collection_order_by(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Name], [l].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Include_reference_ThenInclude_collection_order_by(bool async) + { + await base.Include_reference_ThenInclude_collection_order_by(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Optional_Inverse3Id] +ORDER BY [l].[Name], [l].[Id], [l0].[Id], [l1].[Id]"); + } + + public override async Task Include_collection_then_reference(bool async) + { + await base.Include_collection_then_reference(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [t].[Id], [t].[Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Optional_Self_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToMany_Required_Self_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t].[OneToOne_Optional_Self2Id], [t].[Id0], [t].[Level2_Optional_Id], [t].[Level2_Required_Id], [t].[Name0], [t].[OneToMany_Optional_Inverse3Id], [t].[OneToMany_Optional_Self_Inverse3Id], [t].[OneToMany_Required_Inverse3Id], [t].[OneToMany_Required_Self_Inverse3Id], [t].[OneToOne_Optional_PK_Inverse3Id], [t].[OneToOne_Optional_Self3Id] +FROM [LevelOne] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id], [l1].[Id] AS [Id0], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id] + FROM [LevelTwo] AS [l0] + LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[Level2_Optional_Id] +) AS [t] ON [l].[Id] = [t].[OneToMany_Optional_Inverse2Id] +ORDER BY [l].[Id], [t].[Id], [t].[Id0]"); + } + + public override async Task Include_reference_and_project_into_anonymous_type(bool async) + { + await base.Include_reference_and_project_into_anonymous_type(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id]"); + } + + public override async Task Include_collection_with_conditional_order_by(bool async) + { + await base.Include_collection_with_conditional_order_by(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Id], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[OneToMany_Optional_Inverse2Id] +ORDER BY CASE + WHEN [l].[Name] IS NOT NULL AND ([l].[Name] LIKE N'%03') THEN 1 + ELSE 2 +END, [l].[Id], [l0].[Id]"); + } + public override async Task Multiple_complex_include_select(bool async) { await base.Multiple_complex_include_select(async); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServerTest.cs index d6ca5357653..56476a50464 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServerTest.cs @@ -638,9 +638,9 @@ public override async Task Where_math_abs1(bool async) await base.Where_math_abs1(async); AssertSql( - @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] -WHERE ABS([o].[ProductID]) > 10"); + @"SELECT [p].[ProductID], [p].[Discontinued], [p].[ProductName], [p].[SupplierID], [p].[UnitPrice], [p].[UnitsInStock] +FROM [Products] AS [p] +WHERE ABS([p].[ProductID]) > 10"); } public override async Task Where_math_abs2(bool async) @@ -650,7 +650,7 @@ public override async Task Where_math_abs2(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] FROM [Order Details] AS [o] -WHERE ABS([o].[Quantity]) > CAST(10 AS smallint)"); +WHERE ([o].[UnitPrice] < 7.0) AND (ABS([o].[Quantity]) > CAST(10 AS smallint))"); } public override async Task Where_math_abs3(bool async) @@ -660,7 +660,7 @@ public override async Task Where_math_abs3(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] FROM [Order Details] AS [o] -WHERE ABS([o].[UnitPrice]) > 10.0"); +WHERE ([o].[Quantity] < CAST(5 AS smallint)) AND (ABS([o].[UnitPrice]) > 10.0)"); } public override async Task Where_math_abs_uncorrelated(bool async) @@ -670,7 +670,7 @@ public override async Task Where_math_abs_uncorrelated(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] FROM [Order Details] AS [o] -WHERE 10 < [o].[ProductID]"); +WHERE ([o].[UnitPrice] < 7.0) AND (10 < [o].[ProductID])"); } public override async Task Where_math_ceiling1(bool async) @@ -680,7 +680,7 @@ public override async Task Where_math_ceiling1(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] FROM [Order Details] AS [o] -WHERE CEILING(CAST([o].[Discount] AS float)) > 0.0E0"); +WHERE ([o].[UnitPrice] < 7.0) AND (CEILING(CAST([o].[Discount] AS float)) > 0.0E0)"); } public override async Task Where_math_ceiling2(bool async) @@ -690,7 +690,7 @@ public override async Task Where_math_ceiling2(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] FROM [Order Details] AS [o] -WHERE CEILING([o].[UnitPrice]) > 10.0"); +WHERE ([o].[Quantity] < CAST(5 AS smallint)) AND (CEILING([o].[UnitPrice]) > 10.0)"); } public override async Task Where_math_floor(bool async) @@ -700,7 +700,7 @@ public override async Task Where_math_floor(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] FROM [Order Details] AS [o] -WHERE FLOOR([o].[UnitPrice]) > 10.0"); +WHERE ([o].[Quantity] < CAST(5 AS smallint)) AND (FLOOR([o].[UnitPrice]) > 10.0)"); } public override async Task Where_math_power(bool async) @@ -720,7 +720,7 @@ public override async Task Where_math_round(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] FROM [Order Details] AS [o] -WHERE ROUND([o].[UnitPrice], 0) > 10.0"); +WHERE ([o].[Quantity] < CAST(5 AS smallint)) AND (ROUND([o].[UnitPrice], 0) > 10.0)"); } public override async Task Select_math_round_int(bool async) @@ -760,7 +760,7 @@ public override async Task Where_math_truncate(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] FROM [Order Details] AS [o] -WHERE ROUND([o].[UnitPrice], 0, 1) > 10.0"); +WHERE ([o].[Quantity] < CAST(5 AS smallint)) AND (ROUND([o].[UnitPrice], 0, 1) > 10.0)"); } public override async Task Where_math_exp(bool async) @@ -906,8 +906,8 @@ public override async Task Where_guid_newguid(bool async) await base.Where_guid_newguid(async); AssertSql( - @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice] -FROM [Order Details] AS [o] + @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] WHERE NEWID() <> '00000000-0000-0000-0000-000000000000'"); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs index c5527c6ecce..879c93fd73d 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs @@ -37,6 +37,7 @@ LEFT JOIN ( FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] ) AS [t] ON [p].[ProductID] = [t].[ProductID] +WHERE (([p].[ProductID] % 17) = 5) AND ([p].[UnitPrice] < 20.0) ORDER BY [p].[ProductID], [t].[OrderID], [t].[ProductID], [t].[OrderID0]"); } @@ -47,7 +48,8 @@ public override async Task Include_reference(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Orders] AS [o] -LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID]"); +LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID] +WHERE [o].[CustomerID] IS NOT NULL AND ([o].[CustomerID] LIKE N'F%')"); } public override async Task Include_when_result_operator(bool async) @@ -71,6 +73,7 @@ public override async Task Include_collection(bool async) @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID], [o].[OrderID]"); } @@ -151,6 +154,7 @@ public override async Task Include_reference_and_collection(bool async) FROM [Orders] AS [o] LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID] LEFT JOIN [Order Details] AS [o0] ON [o].[OrderID] = [o0].[OrderID] +WHERE [o].[CustomerID] IS NOT NULL AND ([o].[CustomerID] LIKE N'F%') ORDER BY [o].[OrderID], [c].[CustomerID], [o0].[OrderID], [o0].[ProductID]"); } @@ -178,7 +182,8 @@ public override async Task Include_references_multi_level(bool async) @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate], [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] -LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID]"); +LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID] +WHERE ([o].[OrderID] % 23) = 13"); } public override async Task Include_multiple_references_multi_level(bool async) @@ -190,7 +195,8 @@ public override async Task Include_multiple_references_multi_level(bool async) FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID] -INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID]"); +INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID] +WHERE ([o].[OrderID] % 23) = 13"); } public override async Task Include_multiple_references_multi_level_reverse(bool async) @@ -202,7 +208,8 @@ public override async Task Include_multiple_references_multi_level_reverse(bool FROM [Order Details] AS [o] INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] -LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID]"); +LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID] +WHERE ([o].[OrderID] % 23) = 13"); } public override async Task Include_references_and_collection_multi_level(bool async) @@ -215,6 +222,7 @@ FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID] LEFT JOIN [Orders] AS [o1] ON [c].[CustomerID] = [o1].[CustomerID] +WHERE (([o].[OrderID] % 23) = 13) AND ([o].[UnitPrice] < 10.0) ORDER BY [o].[OrderID], [o].[ProductID], [o0].[OrderID], [c].[CustomerID], [o1].[OrderID]"); } @@ -261,6 +269,7 @@ public override async Task Include_collection_alias_generation(bool async) @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [o0].[OrderID], [o0].[ProductID], [o0].[Discount], [o0].[Quantity], [o0].[UnitPrice] FROM [Orders] AS [o] LEFT JOIN [Order Details] AS [o0] ON [o].[OrderID] = [o0].[OrderID] +WHERE [o].[CustomerID] IS NOT NULL AND ([o].[CustomerID] LIKE N'F%') ORDER BY [o].[OrderID], [o0].[OrderID], [o0].[ProductID]"); } @@ -296,6 +305,7 @@ public override async Task Include_collection_order_by_key(bool async) @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID], [o].[OrderID]"); } @@ -307,6 +317,7 @@ public override async Task Include_collection_order_by_non_key(bool async) @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[PostalCode], [c].[CustomerID], [o].[OrderID]"); } @@ -332,12 +343,13 @@ public override async Task Include_collection_order_by_non_key_with_skip(bool as await base.Include_collection_order_by_non_key_with_skip(async); AssertSql( - @"@__p_0='10' + @"@__p_0='2' SELECT [t].[CustomerID], [t].[Address], [t].[City], [t].[CompanyName], [t].[ContactName], [t].[ContactTitle], [t].[Country], [t].[Fax], [t].[Phone], [t].[PostalCode], [t].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM ( SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] + WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[ContactTitle] OFFSET @__p_0 ROWS ) AS [t] @@ -439,6 +451,7 @@ LEFT JOIN ( FROM [Orders] AS [o] LEFT JOIN [Order Details] AS [o0] ON [o].[OrderID] = [o0].[OrderID] ) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID], [t].[OrderID], [t].[OrderID0], [t].[ProductID]"); } @@ -458,6 +471,7 @@ FROM [Order Details] AS [o0] INNER JOIN [Products] AS [p] ON [o0].[ProductID] = [p].[ProductID] ) AS [t] ON [o].[OrderID] = [t].[OrderID] ) AS [t0] ON [c].[CustomerID] = [t0].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID], [t0].[OrderID], [t0].[OrderID0], [t0].[ProductID], [t0].[ProductID0]"); } @@ -572,15 +586,19 @@ public override async Task Include_collection_on_additional_from_clause(bool asy AssertSql( @"@__p_0='5' -SELECT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region], [t].[CustomerID], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] +SELECT [t0].[CustomerID], [t0].[Address], [t0].[City], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Country], [t0].[Fax], [t0].[Phone], [t0].[PostalCode], [t0].[Region], [t].[CustomerID], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM ( SELECT TOP(@__p_0) [c].[CustomerID] FROM [Customers] AS [c] ORDER BY [c].[CustomerID] ) AS [t] -CROSS JOIN [Customers] AS [c0] -LEFT JOIN [Orders] AS [o] ON [c0].[CustomerID] = [o].[CustomerID] -ORDER BY [t].[CustomerID], [c0].[CustomerID], [o].[OrderID]"); +CROSS JOIN ( + SELECT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region] + FROM [Customers] AS [c0] + WHERE [c0].[CustomerID] LIKE N'F%' +) AS [t0] +LEFT JOIN [Orders] AS [o] ON [t0].[CustomerID] = [o].[CustomerID] +ORDER BY [t].[CustomerID], [t0].[CustomerID], [o].[OrderID]"); } public override async Task Include_duplicate_collection(bool async) @@ -740,7 +758,8 @@ public override async Task Include_multiple_references(bool async) @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate], [p].[ProductID], [p].[Discontinued], [p].[ProductName], [p].[SupplierID], [p].[UnitPrice], [p].[UnitsInStock] FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] -INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID]"); +INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID] +WHERE ([o].[OrderID] % 23) = 13"); } public override async Task Include_reference_alias_generation(bool async) @@ -750,7 +769,8 @@ public override async Task Include_reference_alias_generation(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] FROM [Order Details] AS [o] -INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID]"); +INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] +WHERE ([o].[OrderID] % 23) = 13"); } public override async Task Include_duplicate_reference(bool async) @@ -1016,6 +1036,7 @@ public override async Task Include_collection_with_conditional_order_by(bool asy @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY CASE WHEN [c].[CustomerID] LIKE N'S%' THEN 1 ELSE 2 diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindJoinQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindJoinQuerySqlServerTest.cs index 02bd8ca936c..b43bcb001e6 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindJoinQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindJoinQuerySqlServerTest.cs @@ -38,7 +38,8 @@ public override async Task Join_customers_orders_entities(bool async) AssertSql( @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] -INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID]"); +INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%'"); } public override async Task Join_select_many(bool async) @@ -49,7 +50,8 @@ public override async Task Join_select_many(bool async) @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] -CROSS JOIN [Employees] AS [e]"); +CROSS JOIN [Employees] AS [e] +WHERE [c].[CustomerID] LIKE N'F%'"); } public override async Task Client_Join_select_many(bool async) @@ -204,7 +206,8 @@ public override async Task Join_composite_key(bool async) AssertSql( @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] -INNER JOIN [Orders] AS [o] ON ([c].[CustomerID] = [o].[CustomerID]) AND ([c].[CustomerID] = [o].[CustomerID])"); +INNER JOIN [Orders] AS [o] ON ([c].[CustomerID] = [o].[CustomerID]) AND ([c].[CustomerID] = [o].[CustomerID]) +WHERE [c].[CustomerID] LIKE N'F%'"); } public override async Task Join_complex_condition(bool async) @@ -240,7 +243,8 @@ public override async Task Join_same_collection_force_alias_uniquefication(bool AssertSql( @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] FROM [Orders] AS [o] -INNER JOIN [Orders] AS [o0] ON [o].[CustomerID] = [o0].[CustomerID]"); +INNER JOIN [Orders] AS [o0] ON [o].[CustomerID] = [o0].[CustomerID] +WHERE [o].[CustomerID] IS NOT NULL AND ([o].[CustomerID] LIKE N'F%')"); } public override async Task GroupJoin_simple(bool async) @@ -250,7 +254,8 @@ public override async Task GroupJoin_simple(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] -INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID]"); +INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%'"); } public override async Task GroupJoin_simple2(bool async) @@ -281,6 +286,7 @@ public override async Task GroupJoin_simple_ordering(bool async) @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[City]"); } @@ -307,7 +313,8 @@ public override async Task GroupJoin_DefaultIfEmpty(bool async) AssertSql( @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] -LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID]"); +LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%'"); } public override async Task GroupJoin_DefaultIfEmpty_multiple(bool async) @@ -318,7 +325,8 @@ public override async Task GroupJoin_DefaultIfEmpty_multiple(bool async) @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] FROM [Customers] AS [c] LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] -LEFT JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID]"); +LEFT JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%'"); } public override async Task GroupJoin_DefaultIfEmpty2(bool async) @@ -326,9 +334,13 @@ public override async Task GroupJoin_DefaultIfEmpty2(bool async) await base.GroupJoin_DefaultIfEmpty2(async); AssertSql( - @"SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] + @"SELECT [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title], [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] FROM [Employees] AS [e] -LEFT JOIN [Orders] AS [o] ON [e].[EmployeeID] = [o].[EmployeeID]"); +LEFT JOIN ( + SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] + FROM [Orders] AS [o] + WHERE [o].[CustomerID] IS NOT NULL AND ([o].[CustomerID] LIKE N'F%') +) AS [t] ON [e].[EmployeeID] = [t].[EmployeeID]"); } public override async Task GroupJoin_DefaultIfEmpty3(bool async) @@ -440,7 +452,8 @@ LEFT JOIN ( SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Orders] AS [o] WHERE [o].[OrderID] > 5 -) AS [t] ON [c].[CustomerID] = [t].[CustomerID]"); +) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%'"); } public override async Task GroupJoin_SelectMany_subquery_with_filter_orderby_and_DefaultIfEmpty(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs index f8df3480d80..d17205753f4 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs @@ -30,6 +30,7 @@ public override async Task Include_list(bool async) AssertSql( @"SELECT [p].[ProductID], [p].[Discontinued], [p].[ProductName], [p].[SupplierID], [p].[UnitPrice], [p].[UnitsInStock] FROM [Products] AS [p] +WHERE (([p].[ProductID] % 17) = 5) AND ([p].[UnitPrice] < 20.0) ORDER BY [p].[ProductID]", // @"SELECT [t].[OrderID], [t].[ProductID], [t].[Discount], [t].[Quantity], [t].[UnitPrice], [t].[OrderID0], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate], [p].[ProductID] @@ -39,6 +40,7 @@ INNER JOIN ( FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] ) AS [t] ON [p].[ProductID] = [t].[ProductID] +WHERE (([p].[ProductID] % 17) = 5) AND ([p].[UnitPrice] < 20.0) ORDER BY [p].[ProductID]"); } @@ -49,7 +51,8 @@ public override async Task Include_reference(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Orders] AS [o] -LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID]"); +LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID] +WHERE [o].[CustomerID] IS NOT NULL AND ([o].[CustomerID] LIKE N'F%')"); } public override async Task Include_when_result_operator(bool async) @@ -72,11 +75,13 @@ public override async Task Include_collection(bool async) AssertSql( @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID]", // @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[CustomerID] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID]"); } @@ -175,12 +180,14 @@ public override async Task Include_reference_and_collection(bool async) @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Orders] AS [o] LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID] +WHERE [o].[CustomerID] IS NOT NULL AND ([o].[CustomerID] LIKE N'F%') ORDER BY [o].[OrderID], [c].[CustomerID]", // @"SELECT [o0].[OrderID], [o0].[ProductID], [o0].[Discount], [o0].[Quantity], [o0].[UnitPrice], [o].[OrderID], [c].[CustomerID] FROM [Orders] AS [o] LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID] INNER JOIN [Order Details] AS [o0] ON [o].[OrderID] = [o0].[OrderID] +WHERE [o].[CustomerID] IS NOT NULL AND ([o].[CustomerID] LIKE N'F%') ORDER BY [o].[OrderID], [c].[CustomerID]"); } @@ -209,7 +216,8 @@ public override async Task Include_references_multi_level(bool async) @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate], [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] -LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID]"); +LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID] +WHERE ([o].[OrderID] % 23) = 13"); } public override async Task Include_multiple_references_multi_level(bool async) @@ -221,7 +229,8 @@ public override async Task Include_multiple_references_multi_level(bool async) FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID] -INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID]"); +INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID] +WHERE ([o].[OrderID] % 23) = 13"); } public override async Task Include_multiple_references_multi_level_reverse(bool async) @@ -233,7 +242,8 @@ public override async Task Include_multiple_references_multi_level_reverse(bool FROM [Order Details] AS [o] INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] -LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID]"); +LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID] +WHERE ([o].[OrderID] % 23) = 13"); } public override async Task Include_references_and_collection_multi_level(bool async) @@ -245,6 +255,7 @@ public override async Task Include_references_and_collection_multi_level(bool as FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID] +WHERE (([o].[OrderID] % 23) = 13) AND ([o].[UnitPrice] < 10.0) ORDER BY [o].[OrderID], [o].[ProductID], [o0].[OrderID], [c].[CustomerID]", // @"SELECT [o1].[OrderID], [o1].[CustomerID], [o1].[EmployeeID], [o1].[OrderDate], [o].[OrderID], [o].[ProductID], [o0].[OrderID], [c].[CustomerID] @@ -252,6 +263,7 @@ FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] LEFT JOIN [Customers] AS [c] ON [o0].[CustomerID] = [c].[CustomerID] INNER JOIN [Orders] AS [o1] ON [c].[CustomerID] = [o1].[CustomerID] +WHERE (([o].[OrderID] % 23) = 13) AND ([o].[UnitPrice] < 10.0) ORDER BY [o].[OrderID], [o].[ProductID], [o0].[OrderID], [c].[CustomerID]"); } @@ -314,11 +326,13 @@ public override async Task Include_collection_alias_generation(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Orders] AS [o] +WHERE [o].[CustomerID] IS NOT NULL AND ([o].[CustomerID] LIKE N'F%') ORDER BY [o].[OrderID]", // @"SELECT [o0].[OrderID], [o0].[ProductID], [o0].[Discount], [o0].[Quantity], [o0].[UnitPrice], [o].[OrderID] FROM [Orders] AS [o] INNER JOIN [Order Details] AS [o0] ON [o].[OrderID] = [o0].[OrderID] +WHERE [o].[CustomerID] IS NOT NULL AND ([o].[CustomerID] LIKE N'F%') ORDER BY [o].[OrderID]"); } @@ -370,11 +384,13 @@ public override async Task Include_collection_order_by_key(bool async) AssertSql( @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID]", // @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[CustomerID] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID]"); } @@ -385,11 +401,13 @@ public override async Task Include_collection_order_by_non_key(bool async) AssertSql( @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[PostalCode], [c].[CustomerID]", // @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[CustomerID] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[PostalCode], [c].[CustomerID]"); } @@ -425,23 +443,25 @@ public override async Task Include_collection_order_by_non_key_with_skip(bool as await base.Include_collection_order_by_non_key_with_skip(async); AssertSql( - @"@__p_0='10' + @"@__p_0='2' SELECT [t].[CustomerID], [t].[Address], [t].[City], [t].[CompanyName], [t].[ContactName], [t].[ContactTitle], [t].[Country], [t].[Fax], [t].[Phone], [t].[PostalCode], [t].[Region] FROM ( SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] + WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[ContactTitle] OFFSET @__p_0 ROWS ) AS [t] ORDER BY [t].[ContactTitle], [t].[CustomerID]", // - @"@__p_0='10' + @"@__p_0='2' SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [t].[CustomerID] FROM ( SELECT [c].[CustomerID], [c].[ContactTitle] FROM [Customers] AS [c] + WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[ContactTitle] OFFSET @__p_0 ROWS ) AS [t] @@ -581,17 +601,20 @@ public override async Task Include_collection_then_include_collection(bool async AssertSql( @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID]", // @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[CustomerID] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID], [o].[OrderID]", // @"SELECT [o0].[OrderID], [o0].[ProductID], [o0].[Discount], [o0].[Quantity], [o0].[UnitPrice], [c].[CustomerID], [o].[OrderID] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] INNER JOIN [Order Details] AS [o0] ON [o].[OrderID] = [o0].[OrderID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID], [o].[OrderID]"); } @@ -602,11 +625,13 @@ public override async Task Include_collection_then_include_collection_then_inclu AssertSql( @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID]", // @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[CustomerID] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID], [o].[OrderID]", // @"SELECT [t].[OrderID], [t].[ProductID], [t].[Discount], [t].[Quantity], [t].[UnitPrice], [t].[ProductID0], [t].[Discontinued], [t].[ProductName], [t].[SupplierID], [t].[UnitPrice0], [t].[UnitsInStock], [c].[CustomerID], [o].[OrderID] @@ -617,6 +642,7 @@ INNER JOIN ( FROM [Order Details] AS [o0] INNER JOIN [Products] AS [p] ON [o0].[ProductID] = [p].[ProductID] ) AS [t] ON [o].[OrderID] = [t].[OrderID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY [c].[CustomerID], [o].[OrderID]"); } @@ -784,26 +810,34 @@ public override async Task Include_collection_on_additional_from_clause(bool asy AssertSql( @"@__p_0='5' -SELECT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region], [t].[CustomerID] +SELECT [t0].[CustomerID], [t0].[Address], [t0].[City], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Country], [t0].[Fax], [t0].[Phone], [t0].[PostalCode], [t0].[Region], [t].[CustomerID] FROM ( SELECT TOP(@__p_0) [c].[CustomerID] FROM [Customers] AS [c] ORDER BY [c].[CustomerID] ) AS [t] -CROSS JOIN [Customers] AS [c0] -ORDER BY [t].[CustomerID], [c0].[CustomerID]", +CROSS JOIN ( + SELECT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region] + FROM [Customers] AS [c0] + WHERE [c0].[CustomerID] LIKE N'F%' +) AS [t0] +ORDER BY [t].[CustomerID], [t0].[CustomerID]", // @"@__p_0='5' -SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [t].[CustomerID], [c0].[CustomerID] +SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [t].[CustomerID], [t0].[CustomerID] FROM ( SELECT TOP(@__p_0) [c].[CustomerID] FROM [Customers] AS [c] ORDER BY [c].[CustomerID] ) AS [t] -CROSS JOIN [Customers] AS [c0] -INNER JOIN [Orders] AS [o] ON [c0].[CustomerID] = [o].[CustomerID] -ORDER BY [t].[CustomerID], [c0].[CustomerID]"); +CROSS JOIN ( + SELECT [c0].[CustomerID] + FROM [Customers] AS [c0] + WHERE [c0].[CustomerID] LIKE N'F%' +) AS [t0] +INNER JOIN [Orders] AS [o] ON [t0].[CustomerID] = [o].[CustomerID] +ORDER BY [t].[CustomerID], [t0].[CustomerID]"); } public override async Task Include_duplicate_collection(bool async) @@ -1075,7 +1109,8 @@ public override async Task Include_multiple_references(bool async) @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate], [p].[ProductID], [p].[Discontinued], [p].[ProductName], [p].[SupplierID], [p].[UnitPrice], [p].[UnitsInStock] FROM [Order Details] AS [o] INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] -INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID]"); +INNER JOIN [Products] AS [p] ON [o].[ProductID] = [p].[ProductID] +WHERE ([o].[OrderID] % 23) = 13"); } public override async Task Include_reference_alias_generation(bool async) @@ -1085,7 +1120,8 @@ public override async Task Include_reference_alias_generation(bool async) AssertSql( @"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] FROM [Order Details] AS [o] -INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID]"); +INNER JOIN [Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID] +WHERE ([o].[OrderID] % 23) = 13"); } public override async Task Include_duplicate_reference(bool async) @@ -1434,6 +1470,7 @@ public override async Task Include_collection_with_conditional_order_by(bool asy AssertSql( @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY CASE WHEN [c].[CustomerID] LIKE N'S%' THEN 1 ELSE 2 @@ -1442,6 +1479,7 @@ ELSE 2 @"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[CustomerID] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +WHERE [c].[CustomerID] LIKE N'F%' ORDER BY CASE WHEN [c].[CustomerID] LIKE N'S%' THEN 1 ELSE 2 diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindFunctionsQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindFunctionsQuerySqliteTest.cs index 2bbcdf4e00e..aaff31d89fb 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindFunctionsQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindFunctionsQuerySqliteTest.cs @@ -346,9 +346,9 @@ public override async Task Where_math_abs1(bool async) await base.Where_math_abs1(async); AssertSql( - @"SELECT ""o"".""OrderID"", ""o"".""ProductID"", ""o"".""Discount"", ""o"".""Quantity"", ""o"".""UnitPrice"" -FROM ""Order Details"" AS ""o"" -WHERE abs(""o"".""ProductID"") > 10"); + @"SELECT ""p"".""ProductID"", ""p"".""Discontinued"", ""p"".""ProductName"", ""p"".""SupplierID"", ""p"".""UnitPrice"", ""p"".""UnitsInStock"" +FROM ""Products"" AS ""p"" +WHERE abs(""p"".""ProductID"") > 10"); } public override async Task Where_math_abs2(bool async) @@ -358,7 +358,7 @@ public override async Task Where_math_abs2(bool async) AssertSql( @"SELECT ""o"".""OrderID"", ""o"".""ProductID"", ""o"".""Discount"", ""o"".""Quantity"", ""o"".""UnitPrice"" FROM ""Order Details"" AS ""o"" -WHERE abs(""o"".""Quantity"") > 10"); +WHERE (""o"".""UnitPrice"" < 7.0) AND (abs(""o"".""Quantity"") > 10)"); } public override async Task Where_math_abs_uncorrelated(bool async) @@ -368,7 +368,7 @@ public override async Task Where_math_abs_uncorrelated(bool async) AssertSql( @"SELECT ""o"".""OrderID"", ""o"".""ProductID"", ""o"".""Discount"", ""o"".""Quantity"", ""o"".""UnitPrice"" FROM ""Order Details"" AS ""o"" -WHERE 10 < ""o"".""ProductID"""); +WHERE (""o"".""UnitPrice"" < 7.0) AND (10 < ""o"".""ProductID"")"); } public override async Task Select_math_round_int(bool async)