Skip to content

Commit 6f33e42

Browse files
authored
Translate COALESCE as ISNULL (#34171)
1 parent 0024b2b commit 6f33e42

21 files changed

+211
-61
lines changed

src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,53 @@ protected override Expression VisitValues(ValuesExpression valuesExpression)
202202
return valuesExpression;
203203
}
204204

205+
/// <summary>
206+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
207+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
208+
/// any release. You should only use it directly in your code with extreme caution and knowing that
209+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
210+
/// </summary>
211+
protected override Expression VisitSqlFunction(SqlFunctionExpression sqlFunctionExpression)
212+
{
213+
if (sqlFunctionExpression is { IsBuiltIn: true, Arguments: not null }
214+
&& string.Equals(sqlFunctionExpression.Name, "COALESCE", StringComparison.OrdinalIgnoreCase))
215+
{
216+
var type = sqlFunctionExpression.Type;
217+
var typeMapping = sqlFunctionExpression.TypeMapping;
218+
var defaultTypeMapping = _typeMappingSource.FindMapping(type);
219+
220+
// ISNULL always return a value having the same type as its first
221+
// argument. Ideally we would convert the argument to have the
222+
// desired type and type mapping, but currently EFCore has some
223+
// trouble in computing types of non-homogeneous expressions
224+
// (tracked in https://github.com/dotnet/efcore/issues/15586). To
225+
// stay on the safe side we only use ISNULL if:
226+
// - all sub-expressions have the same type as the expression
227+
// - all sub-expressions have the same type mapping as the expression
228+
// - the expression is using the default type mapping (combined
229+
// with the two above, this implies that all of the expressions
230+
// are using the default type mapping of the type)
231+
if (defaultTypeMapping == typeMapping
232+
&& sqlFunctionExpression.Arguments.All(a => a.Type == type && a.TypeMapping == typeMapping)) {
233+
234+
var head = sqlFunctionExpression.Arguments[0];
235+
sqlFunctionExpression = (SqlFunctionExpression)sqlFunctionExpression
236+
.Arguments
237+
.Skip(1)
238+
.Aggregate(head, (l, r) => new SqlFunctionExpression(
239+
"ISNULL",
240+
arguments: [l, r],
241+
nullable: true,
242+
argumentsPropagateNullability: [false, false],
243+
sqlFunctionExpression.Type,
244+
sqlFunctionExpression.TypeMapping
245+
));
246+
}
247+
}
248+
249+
return base.VisitSqlFunction(sqlFunctionExpression);
250+
}
251+
205252
/// <summary>
206253
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
207254
/// the same compatibility standards as public APIs. It may be changed or removed without notice in

test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3229,6 +3229,49 @@ public override async Task Entity_equality_orderby_descending_subquery_composite
32293229
AssertSql();
32303230
}
32313231

3232+
public override Task Coalesce_Correct_Multiple_Same_TypeMapping(bool async)
3233+
=> Fixture.NoSyncTest(
3234+
async, async a =>
3235+
{
3236+
await base.Coalesce_Correct_Multiple_Same_TypeMapping(async);
3237+
3238+
AssertSql(
3239+
"""
3240+
SELECT VALUE
3241+
{
3242+
"ReportsTo" : c["ReportsTo"],
3243+
"c" : 1,
3244+
"c0" : 2,
3245+
"c1" : 3
3246+
}
3247+
FROM root c
3248+
ORDER BY c["EmployeeID"]
3249+
""");
3250+
});
3251+
3252+
public override Task Coalesce_Correct_TypeMapping_Double(bool async)
3253+
=> Fixture.NoSyncTest(
3254+
async, async a =>
3255+
{
3256+
await base.Coalesce_Correct_TypeMapping_Double(async);
3257+
3258+
AssertSql();
3259+
});
3260+
3261+
public override Task Coalesce_Correct_TypeMapping_String(bool async)
3262+
=> Fixture.NoSyncTest(
3263+
async, async a =>
3264+
{
3265+
await base.Coalesce_Correct_TypeMapping_String(async);
3266+
3267+
AssertSql(
3268+
"""
3269+
SELECT VALUE ((c["Region"] != null) ? c["Region"] : "no region specified")
3270+
FROM root c
3271+
ORDER BY c["id"]
3272+
""");
3273+
});
3274+
32323275
public override async Task Null_Coalesce_Short_Circuit(bool async)
32333276
{
32343277
// Cosmos client evaluation. Issue #17246.
@@ -3347,7 +3390,7 @@ public override async Task SelectMany_primitive_select_subquery(bool async)
33473390
// Cosmos client evaluation. Issue #17246.
33483391
Assert.Equal(
33493392
CoreStrings.ExpressionParameterizationExceptionSensitive(
3350-
"value(Microsoft.EntityFrameworkCore.Query.NorthwindMiscellaneousQueryTestBase`1+<>c__DisplayClass172_0[Microsoft.EntityFrameworkCore.Query.NorthwindQueryCosmosFixture`1[Microsoft.EntityFrameworkCore.TestUtilities.NoopModelCustomizer]]).ss.Set().Any()"),
3393+
"value(Microsoft.EntityFrameworkCore.Query.NorthwindMiscellaneousQueryTestBase`1+<>c__DisplayClass175_0[Microsoft.EntityFrameworkCore.Query.NorthwindQueryCosmosFixture`1[Microsoft.EntityFrameworkCore.TestUtilities.NoopModelCustomizer]]).ss.Set().Any()"),
33513394
(await Assert.ThrowsAsync<InvalidOperationException>(
33523395
() => base.SelectMany_primitive_select_subquery(async))).Message);
33533396

test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,31 @@ public virtual Task Ternary_should_not_evaluate_both_sides_with_parameter(bool a
723723
}));
724724
}
725725

726+
[ConditionalTheory]
727+
[MemberData(nameof(IsAsyncData))]
728+
public virtual Task Coalesce_Correct_Multiple_Same_TypeMapping(bool async)
729+
=> AssertQuery(
730+
async,
731+
ss => ss.Set<Employee>().OrderBy(e => e.EmployeeID)
732+
.Select(e => (e.ReportsTo + 1L) ?? (e.ReportsTo + 2L) ?? (e.ReportsTo + 3L)),
733+
assertOrder: true);
734+
735+
[ConditionalTheory(Skip = "issue #15586")]
736+
[MemberData(nameof(IsAsyncData))]
737+
public virtual Task Coalesce_Correct_TypeMapping_Double(bool async)
738+
=> AssertQuery(
739+
async,
740+
ss => ss.Set<Employee>().OrderBy(e => e.EmployeeID).Select(e => e.ReportsTo ?? 2.25),
741+
assertOrder: true);
742+
743+
[ConditionalTheory]
744+
[MemberData(nameof(IsAsyncData))]
745+
public virtual Task Coalesce_Correct_TypeMapping_String(bool async)
746+
=> AssertQuery(
747+
async,
748+
ss => ss.Set<Customer>().OrderBy(c => c.CustomerID).Select(c => c.Region ?? "no region specified"),
749+
assertOrder: true);
750+
726751
[ConditionalTheory]
727752
[MemberData(nameof(IsAsyncData))]
728753
public virtual Task Null_Coalesce_Short_Circuit(bool async)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3980,7 +3980,7 @@ public override async Task Nested_object_constructed_from_group_key_properties(b
39803980

39813981
AssertSql(
39823982
"""
3983-
SELECT [l].[Id], [l].[Name], [l].[Date], [l0].[Id], [l1].[Name], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], COALESCE(SUM(CAST(LEN([l].[Name]) AS int)), 0) AS [Aggregate]
3983+
SELECT [l].[Id], [l].[Name], [l].[Date], [l0].[Id], [l1].[Name], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], ISNULL(SUM(CAST(LEN([l].[Name]) AS int)), 0) AS [Aggregate]
39843984
FROM [LevelOne] AS [l]
39853985
LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id]
39863986
LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Required_Id]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3980,7 +3980,7 @@ public override async Task Nested_object_constructed_from_group_key_properties(b
39803980

39813981
AssertSql(
39823982
"""
3983-
SELECT [l].[Id], [l].[Name], [l].[Date], [l0].[Id], [l1].[Name], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], COALESCE(SUM(CAST(LEN([l].[Name]) AS int)), 0) AS [Aggregate]
3983+
SELECT [l].[Id], [l].[Name], [l].[Date], [l0].[Id], [l1].[Name], [l0].[Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], ISNULL(SUM(CAST(LEN([l].[Name]) AS int)), 0) AS [Aggregate]
39843984
FROM [LevelOne] AS [l]
39853985
LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id]
39863986
LEFT JOIN [LevelTwo] AS [l1] ON [l].[Id] = [l1].[Level1_Required_Id]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ public override async Task Nested_object_constructed_from_group_key_properties(b
781781

782782
AssertSql(
783783
"""
784-
SELECT [s].[Id], [s].[Name], [s].[Date], [s].[InnerId] AS [Id], [s].[Level2_Name0] AS [Name], [s].[OneToOne_Required_PK_Date] AS [Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], COALESCE(SUM(CAST(LEN([s].[Name]) AS int)), 0) AS [Aggregate]
784+
SELECT [s].[Id], [s].[Name], [s].[Date], [s].[InnerId] AS [Id], [s].[Level2_Name0] AS [Name], [s].[OneToOne_Required_PK_Date] AS [Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], ISNULL(SUM(CAST(LEN([s].[Name]) AS int)), 0) AS [Aggregate]
785785
FROM (
786786
SELECT [l].[Id], [l].[Date], [l].[Name], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l3].[Level2_Name] AS [Level2_Name0], CASE
787787
WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ public override async Task Nested_object_constructed_from_group_key_properties(b
783783

784784
AssertSql(
785785
"""
786-
SELECT [s].[Id], [s].[Name], [s].[Date], [s].[InnerId] AS [Id], [s].[Level2_Name0] AS [Name], [s].[OneToOne_Required_PK_Date] AS [Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], COALESCE(SUM(CAST(LEN([s].[Name]) AS int)), 0) AS [Aggregate]
786+
SELECT [s].[Id], [s].[Name], [s].[Date], [s].[InnerId] AS [Id], [s].[Level2_Name0] AS [Name], [s].[OneToOne_Required_PK_Date] AS [Date], [s].[Level1_Optional_Id], [s].[Level1_Required_Id], ISNULL(SUM(CAST(LEN([s].[Name]) AS int)), 0) AS [Aggregate]
787787
FROM (
788788
SELECT [l].[Id], [l].[Date], [l].[Name], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l3].[Level2_Name] AS [Level2_Name0], CASE
789789
WHEN [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [l1].[Id]

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,7 +3475,7 @@ public override async Task ToString_nullable_enum_property_projection(bool async
34753475
SELECT CASE [w].[AmmunitionType]
34763476
WHEN 1 THEN N'Cartridge'
34773477
WHEN 2 THEN N'Shell'
3478-
ELSE COALESCE(CAST([w].[AmmunitionType] AS nvarchar(max)), N'')
3478+
ELSE ISNULL(CAST([w].[AmmunitionType] AS nvarchar(max)), N'')
34793479
END
34803480
FROM [Weapons] AS [w]
34813481
""");
@@ -3504,7 +3504,7 @@ FROM [Weapons] AS [w]
35043504
WHERE CASE [w].[AmmunitionType]
35053505
WHEN 1 THEN N'Cartridge'
35063506
WHEN 2 THEN N'Shell'
3507-
ELSE COALESCE(CAST([w].[AmmunitionType] AS nvarchar(max)), N'')
3507+
ELSE ISNULL(CAST([w].[AmmunitionType] AS nvarchar(max)), N'')
35083508
END LIKE N'%Cart%'
35093509
""");
35103510
}
@@ -4883,7 +4883,7 @@ public override async Task Select_subquery_projecting_single_constant_int(bool a
48834883

48844884
AssertSql(
48854885
"""
4886-
SELECT [s].[Name], COALESCE((
4886+
SELECT [s].[Name], ISNULL((
48874887
SELECT TOP(1) 42
48884888
FROM [Gears] AS [g]
48894889
WHERE [s].[Id] = [g].[SquadId] AND [g].[HasSoulPatch] = CAST(1 AS bit)), 0) AS [Gear]
@@ -4911,7 +4911,7 @@ public override async Task Select_subquery_projecting_single_constant_bool(bool
49114911

49124912
AssertSql(
49134913
"""
4914-
SELECT [s].[Name], COALESCE((
4914+
SELECT [s].[Name], ISNULL((
49154915
SELECT TOP(1) CAST(1 AS bit)
49164916
FROM [Gears] AS [g]
49174917
WHERE [s].[Id] = [g].[SquadId] AND [g].[HasSoulPatch] = CAST(1 AS bit)), CAST(0 AS bit)) AS [Gear]
@@ -5546,7 +5546,7 @@ public override async Task String_concat_on_various_types(bool async)
55465546

55475547
AssertSql(
55485548
"""
5549-
SELECT N'HasSoulPatch ' + CAST([g].[HasSoulPatch] AS nvarchar(max)) + N' HasSoulPatch' AS [HasSoulPatch], N'Rank ' + CAST([g].[Rank] AS nvarchar(max)) + N' Rank' AS [Rank], N'SquadId ' + CAST([g].[SquadId] AS nvarchar(max)) + N' SquadId' AS [SquadId], N'Rating ' + COALESCE(CAST([m].[Rating] AS nvarchar(max)), N'') + N' Rating' AS [Rating], N'Timeline ' + CAST([m].[Timeline] AS nvarchar(max)) + N' Timeline' AS [Timeline]
5549+
SELECT N'HasSoulPatch ' + CAST([g].[HasSoulPatch] AS nvarchar(max)) + N' HasSoulPatch' AS [HasSoulPatch], N'Rank ' + CAST([g].[Rank] AS nvarchar(max)) + N' Rank' AS [Rank], N'SquadId ' + CAST([g].[SquadId] AS nvarchar(max)) + N' SquadId' AS [SquadId], N'Rating ' + ISNULL(CAST([m].[Rating] AS nvarchar(max)), N'') + N' Rating' AS [Rating], N'Timeline ' + CAST([m].[Timeline] AS nvarchar(max)) + N' Timeline' AS [Timeline]
55505550
FROM [Gears] AS [g]
55515551
CROSS JOIN [Missions] AS [m]
55525552
ORDER BY [g].[Nickname], [m].[Id]
@@ -6616,7 +6616,7 @@ public override async Task Complex_GroupBy_after_set_operator(bool async)
66166616

66176617
AssertSql(
66186618
"""
6619-
SELECT [u].[Name], [u].[Count], COALESCE(SUM([u].[Count]), 0) AS [Sum]
6619+
SELECT [u].[Name], [u].[Count], ISNULL(SUM([u].[Count]), 0) AS [Sum]
66206620
FROM (
66216621
SELECT [c].[Name], (
66226622
SELECT COUNT(*)
@@ -6642,7 +6642,7 @@ public override async Task Complex_GroupBy_after_set_operator_using_result_selec
66426642

66436643
AssertSql(
66446644
"""
6645-
SELECT [u].[Name], [u].[Count], COALESCE(SUM([u].[Count]), 0) AS [Sum]
6645+
SELECT [u].[Name], [u].[Count], ISNULL(SUM([u].[Count]), 0) AS [Sum]
66466646
FROM (
66476647
SELECT [c].[Name], (
66486648
SELECT COUNT(*)
@@ -9076,7 +9076,7 @@ public override async Task Set_operator_with_navigation_in_projection_groupby_ag
90769076
AssertSql(
90779077
"""
90789078
SELECT [s].[Name], (
9079-
SELECT COALESCE(SUM(CAST(LEN([c].[Location]) AS int)), 0)
9079+
SELECT ISNULL(SUM(CAST(LEN([c].[Location]) AS int)), 0)
90809080
FROM [Gears] AS [g2]
90819081
INNER JOIN [Squads] AS [s0] ON [g2].[SquadId] = [s0].[Id]
90829082
INNER JOIN [Cities] AS [c] ON [g2].[CityOfBirthName] = [c].[Name]
@@ -9160,7 +9160,7 @@ LEFT JOIN (
91609160
SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId], ROW_NUMBER() OVER(PARTITION BY [w].[OwnerFullName] ORDER BY [w].[Id]) AS [row]
91619161
FROM [Weapons] AS [w]
91629162
) AS [w0]
9163-
WHERE [w0].[row] <= COALESCE((
9163+
WHERE [w0].[row] <= ISNULL((
91649164
SELECT [n].[value]
91659165
FROM OPENJSON(@numbers) WITH ([value] int '$') AS [n]
91669166
ORDER BY [n].[value]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ public override async Task Sum_over_uncorrelated_subquery(bool async)
815815
// #34256: rewrite query to avoid "Cannot perform an aggregate function on an expression containing an aggregate or a subquery"
816816
AssertSql(
817817
"""
818-
SELECT COALESCE(SUM([s].[value]), 0)
818+
SELECT ISNULL(SUM([s].[value]), 0)
819819
FROM [Customers] AS [c]
820820
CROSS JOIN (
821821
SELECT COUNT(*) AS [value]
@@ -2721,7 +2721,7 @@ public override async Task Project_constant_Sum(bool async)
27212721

27222722
AssertSql(
27232723
"""
2724-
SELECT COALESCE(SUM(1), 0)
2724+
SELECT ISNULL(SUM(1), 0)
27252725
FROM [Employees] AS [e]
27262726
""");
27272727
}
@@ -3081,7 +3081,7 @@ public override async Task Contains_inside_Sum_without_GroupBy(bool async)
30813081
"""
30823082
@cities='["London","Berlin"]' (Size = 4000)
30833083
3084-
SELECT COALESCE(SUM([s].[value]), 0)
3084+
SELECT ISNULL(SUM([s].[value]), 0)
30853085
FROM [Customers] AS [c]
30863086
OUTER APPLY (
30873087
SELECT CASE

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public override async Task GroupBy_aggregate_projecting_conditional_expression(b
272272
"""
273273
SELECT [o].[OrderDate] AS [Key], CASE
274274
WHEN COUNT(*) = 0 THEN 1
275-
ELSE COALESCE(SUM(CASE
275+
ELSE ISNULL(SUM(CASE
276276
WHEN [o].[OrderID] % 2 = 0 THEN 1
277277
ELSE 0
278278
END), 0) / COUNT(*)
@@ -1939,7 +1939,7 @@ public override async Task GroupBy_Sum_constant(bool async)
19391939

19401940
AssertSql(
19411941
"""
1942-
SELECT COALESCE(SUM(1), 0)
1942+
SELECT ISNULL(SUM(1), 0)
19431943
FROM [Orders] AS [o]
19441944
GROUP BY [o].[CustomerID]
19451945
""");
@@ -2699,7 +2699,7 @@ public override async Task GroupBy_aggregate_followed_by_another_GroupBy_aggrega
26992699

27002700
AssertSql(
27012701
"""
2702-
SELECT [o1].[Key0] AS [Key], COALESCE(SUM([o1].[Count]), 0) AS [Count]
2702+
SELECT [o1].[Key0] AS [Key], ISNULL(SUM([o1].[Count]), 0) AS [Count]
27032703
FROM (
27042704
SELECT [o0].[Count], 1 AS [Key0]
27052705
FROM (

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,9 @@ public override async Task GroupJoin_aggregate_anonymous_key_selectors(bool asyn
596596
await base.GroupJoin_aggregate_anonymous_key_selectors(async);
597597

598598
AssertSql(
599-
"""
599+
"""
600600
SELECT [c].[CustomerID], (
601-
SELECT COALESCE(SUM(CAST(LEN([o].[CustomerID]) AS int)), 0)
601+
SELECT ISNULL(SUM(CAST(LEN([o].[CustomerID]) AS int)), 0)
602602
FROM [Orders] AS [o]
603603
WHERE [c].[City] IS NOT NULL AND [c].[CustomerID] = [o].[CustomerID] AND [c].[City] = N'London') AS [Sum]
604604
FROM [Customers] AS [c]
@@ -610,9 +610,9 @@ public override async Task GroupJoin_aggregate_anonymous_key_selectors2(bool asy
610610
await base.GroupJoin_aggregate_anonymous_key_selectors2(async);
611611

612612
AssertSql(
613-
"""
613+
"""
614614
SELECT [c].[CustomerID], (
615-
SELECT COALESCE(SUM(CAST(LEN([o].[CustomerID]) AS int)), 0)
615+
SELECT ISNULL(SUM(CAST(LEN([o].[CustomerID]) AS int)), 0)
616616
FROM [Orders] AS [o]
617617
WHERE [c].[CustomerID] = [o].[CustomerID] AND 1996 = DATEPART(year, [o].[OrderDate])) AS [Sum]
618618
FROM [Customers] AS [c]
@@ -624,9 +624,9 @@ public override async Task GroupJoin_aggregate_anonymous_key_selectors_one_argum
624624
await base.GroupJoin_aggregate_anonymous_key_selectors_one_argument(async);
625625

626626
AssertSql(
627-
"""
627+
"""
628628
SELECT [c].[CustomerID], (
629-
SELECT COALESCE(SUM(CAST(LEN([o].[CustomerID]) AS int)), 0)
629+
SELECT ISNULL(SUM(CAST(LEN([o].[CustomerID]) AS int)), 0)
630630
FROM [Orders] AS [o]
631631
WHERE [c].[CustomerID] = [o].[CustomerID]) AS [Sum]
632632
FROM [Customers] AS [c]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public override async Task KeylessEntity_groupby(bool async)
148148

149149
AssertSql(
150150
"""
151-
SELECT [m].[City] AS [Key], COUNT(*) AS [Count], COALESCE(SUM(CAST(LEN([m].[Address]) AS int)), 0) AS [Sum]
151+
SELECT [m].[City] AS [Key], COUNT(*) AS [Count], ISNULL(SUM(CAST(LEN([m].[Address]) AS int)), 0) AS [Sum]
152152
FROM (
153153
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]
154154
) AS [m]

0 commit comments

Comments
 (0)