Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public SqlServerObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFact

if (instance.Type == typeof(bool))
{
if (instance is ColumnExpression { IsNullable: true })
if (instance is not ColumnExpression { IsNullable: false })
{
return _sqlExpressionFactory.Case(
instance,
Expand All @@ -92,7 +92,7 @@ public SqlServerObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFact
_sqlExpressionFactory.Constant(true),
_sqlExpressionFactory.Constant(true.ToString()))
},
_sqlExpressionFactory.Constant(null, typeof(string)));
_sqlExpressionFactory.Constant(string.Empty));
}

return _sqlExpressionFactory.Case(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public SqliteObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFactory

if (instance.Type == typeof(bool))
{
if (instance is ColumnExpression { IsNullable: true })
if (instance is not ColumnExpression { IsNullable: false })
{
return _sqlExpressionFactory.Case(
instance,
Expand All @@ -87,7 +87,7 @@ public SqliteObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFactory
_sqlExpressionFactory.Constant(true),
_sqlExpressionFactory.Constant(true.ToString()))
},
_sqlExpressionFactory.Constant(null, typeof(string)));
_sqlExpressionFactory.Constant(string.Empty));
}

return _sqlExpressionFactory.Case(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,20 @@ public virtual Task ToString_boolean_property_non_nullable(bool async)
async,
ss => ss.Set<Weapon>().Select(w => w.IsAutomatic.ToString()));

[ConditionalTheory(Skip = "Issue #33941 Nullable<bool>.ToString() does not match C#")]
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task ToString_boolean_property_nullable(bool async)
=> AssertQuery(
async,
ss => ss.Set<LocustHorde>().Select(lh => lh.Eradicated.ToString()));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task ToString_boolean_computed_nullable(bool async)
=> AssertQuery(
async,
ss => ss.Set<LocustHorde>().Select(lh => (lh.Eradicated | lh.CommanderName == "Unknown").ToString()));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task ToString_enum_property_projection(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3988,7 +3988,26 @@ public override async Task ToString_boolean_property_nullable(bool async)
SELECT CASE [f].[Eradicated]
WHEN CAST(0 AS bit) THEN N'False'
WHEN CAST(1 AS bit) THEN N'True'
ELSE NULL
ELSE N''
END
FROM [Factions] AS [f]
""");
}

[ConditionalTheory(Skip = "Issue #34001 SqlServer never returns null for bool?")]
public override async Task ToString_boolean_computed_nullable(bool async)
{
await base.ToString_boolean_computed_nullable(async);

AssertSql(
"""
SELECT CASE CASE
WHEN NOT ([f].[Eradicated] = CAST(1 AS bit) OR ([f].[CommanderName] = N'Unknown' AND [f].[CommanderName] IS NOT NULL)) THEN CAST(0 AS bit)
WHEN [f].[Eradicated] = CAST(1 AS bit) OR ([f].[CommanderName] = N'Unknown' AND [f].[CommanderName] IS NOT NULL) THEN CAST(1 AS bit)
END
WHEN CAST(0 AS bit) THEN N'False'
WHEN CAST(1 AS bit) THEN N'True'
ELSE N''
END
FROM [Factions] AS [f]
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12638,7 +12638,26 @@ public override async Task ToString_boolean_property_nullable(bool async)
SELECT CASE [l].[Eradicated]
WHEN CAST(0 AS bit) THEN N'False'
WHEN CAST(1 AS bit) THEN N'True'
ELSE NULL
ELSE N''
END
FROM [LocustHordes] AS [l]
""");
}

[ConditionalTheory(Skip = "Issue #34001 SqlServer never returns null for bool?")]
public override async Task ToString_boolean_computed_nullable(bool async)
{
await base.ToString_boolean_computed_nullable(async);

AssertSql(
"""
SELECT CASE CASE
WHEN NOT ([l].[Eradicated] = CAST(1 AS bit) OR ([l].[CommanderName] = N'Unknown' AND [l].[CommanderName] IS NOT NULL)) THEN CAST(0 AS bit)
WHEN [l].[Eradicated] = CAST(1 AS bit) OR ([l].[CommanderName] = N'Unknown' AND [l].[CommanderName] IS NOT NULL) THEN CAST(1 AS bit)
END
WHEN CAST(0 AS bit) THEN N'False'
WHEN CAST(1 AS bit) THEN N'True'
ELSE N''
END
FROM [LocustHordes] AS [l]
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10792,7 +10792,27 @@ public override async Task ToString_boolean_property_nullable(bool async)
SELECT CASE [l].[Eradicated]
WHEN CAST(0 AS bit) THEN N'False'
WHEN CAST(1 AS bit) THEN N'True'
ELSE NULL
ELSE N''
END
FROM [Factions] AS [f]
INNER JOIN [LocustHordes] AS [l] ON [f].[Id] = [l].[Id]
""");
}

[ConditionalTheory(Skip = "Issue #34001 SqlServer never returns null for bool?")]
public override async Task ToString_boolean_computed_nullable(bool async)
{
await base.ToString_boolean_computed_nullable(async);

AssertSql(
"""
SELECT CASE CASE
WHEN NOT ([l].[Eradicated] = CAST(1 AS bit) OR ([l].[CommanderName] = N'Unknown' AND [l].[CommanderName] IS NOT NULL)) THEN CAST(0 AS bit)
WHEN [l].[Eradicated] = CAST(1 AS bit) OR ([l].[CommanderName] = N'Unknown' AND [l].[CommanderName] IS NOT NULL) THEN CAST(1 AS bit)
END
WHEN CAST(0 AS bit) THEN N'False'
WHEN CAST(1 AS bit) THEN N'True'
ELSE N''
END
FROM [Factions] AS [f]
INNER JOIN [LocustHordes] AS [l] ON [f].[Id] = [l].[Id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8264,7 +8264,26 @@ public override async Task ToString_boolean_property_nullable(bool async)
SELECT CASE [f].[Eradicated]
WHEN CAST(0 AS bit) THEN N'False'
WHEN CAST(1 AS bit) THEN N'True'
ELSE NULL
ELSE N''
END
FROM [Factions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [f]
""");
}

[ConditionalTheory(Skip = "Issue #34001 SqlServer never returns null for bool?")]
public override async Task ToString_boolean_computed_nullable(bool async)
{
await base.ToString_boolean_computed_nullable(async);

AssertSql(
"""
SELECT CASE CASE
WHEN NOT ([f].[Eradicated] = CAST(1 AS bit) OR ([f].[CommanderName] = N'Unknown' AND [f].[CommanderName] IS NOT NULL)) THEN CAST(0 AS bit)
WHEN [f].[Eradicated] = CAST(1 AS bit) OR ([f].[CommanderName] = N'Unknown' AND [f].[CommanderName] IS NOT NULL) THEN CAST(1 AS bit)
END
WHEN CAST(0 AS bit) THEN N'False'
WHEN CAST(1 AS bit) THEN N'True'
ELSE N''
END
FROM [Factions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [f]
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6023,7 +6023,22 @@ public override async Task ToString_boolean_property_nullable(bool async)
SELECT CASE "f"."Eradicated"
WHEN 0 THEN 'False'
WHEN 1 THEN 'True'
ELSE NULL
ELSE ''
END
FROM "Factions" AS "f"
""");
}

public override async Task ToString_boolean_computed_nullable(bool async)
{
await base.ToString_boolean_computed_nullable(async);

AssertSql(
"""
SELECT CASE "f"."Eradicated" OR ("f"."CommanderName" = 'Unknown' AND "f"."CommanderName" IS NOT NULL)
WHEN 0 THEN 'False'
WHEN 1 THEN 'True'
ELSE ''
END
FROM "Factions" AS "f"
""");
Expand Down