Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing type mapping for CONVERT #33311

Merged
merged 5 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -102,12 +102,13 @@ public SqlServerObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFact
}

return TypeMapping.TryGetValue(instance.Type, out var storeType)
? _sqlExpressionFactory.Function(
"CONVERT",
new[] { _sqlExpressionFactory.Fragment(storeType), instance },
nullable: true,
argumentsPropagateNullability: new[] { false, true },
typeof(string))
? _sqlExpressionFactory.ApplyDefaultTypeMapping(
cincuranet marked this conversation as resolved.
Show resolved Hide resolved
_sqlExpressionFactory.Function(
"CONVERT",
new[] { _sqlExpressionFactory.Fragment(storeType), instance },
nullable: true,
argumentsPropagateNullability: new[] { false, true },
typeof(string)))
: null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,30 @@ FROM root c
""");
}

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

AssertSql(
"""
SELECT c["OrderID"]
FROM root c
WHERE (c["Discriminator"] = "Order")
""");
}

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

AssertSql(
"""
SELECT c["OrderID"]
FROM root c
WHERE (c["Discriminator"] = "Order")
""");
}

public override Task String_Join_over_non_nullable_column(bool async)
=> AssertTranslationFailed(() => base.String_Join_over_non_nullable_column(async));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1852,4 +1852,18 @@ public virtual Task Where_DateOnly_FromDateTime(bool async)
ss => ss.Set<Order>()
.Where(o => o.OrderDate.HasValue && DateOnly.FromDateTime(o.OrderDate.Value) == new DateOnly(1996, 9, 16))
.AsTracking());

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_ToString_IndexOf(bool async)
=> AssertQuery(
async,
ss => ss.Set<Order>().Select(x => x.OrderID.ToString().IndexOf("123")));
cincuranet marked this conversation as resolved.
Show resolved Hide resolved

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_IndexOf_ToString(bool async)
=> AssertQuery(
async,
ss => ss.Set<Order>().Select(x => "123".IndexOf(x.OrderID.ToString())));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,31 @@ public override Task Regex_IsMatch_MethodCall_constant_input(bool async)
public override Task Datetime_subtraction_TotalDays(bool async)
=> AssertTranslationFailed(() => base.Datetime_subtraction_TotalDays(async));

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

AssertSql(
"""
SELECT CAST(CHARINDEX(N'123', CONVERT(varchar(11), [o].[OrderID])) AS int) - 1
FROM [Orders] AS [o]
""");
}

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

AssertSql(
"""
SELECT CASE
WHEN CONVERT(varchar(11), [o].[OrderID]) = N'' THEN 0
ELSE CAST(CHARINDEX(CONVERT(varchar(11), [o].[OrderID]), N'123') AS int) - 1
END
FROM [Orders] AS [o]
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task StandardDeviation(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,28 @@ public override async Task Where_DateOnly_FromDateTime(bool async)
""");
}

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

AssertSql(
"""
SELECT instr(CAST("o"."OrderID" AS TEXT), '123') - 1
FROM "Orders" AS "o"
""");
}

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

AssertSql(
"""
SELECT instr('123', CAST("o"."OrderID" AS TEXT)) - 1
FROM "Orders" AS "o"
""");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}
Loading