You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We translate Convert<int>(string), but we could also translate x.Parse on the various primitive types (int, long...), as they're a common .NET API. We'd only support the simple overloads accepting a string, nothing more.
Yeah, hopefully One Day(TM) we'll have infra for identifying code inside EF Core expression trees, and then we'd be able to suppress those warnings. This is similar to various string methods, null-ref warnings #21663, etc. - added a note under #22086.
WHERE [o].[CustomerID] = N'ALFKI' AND ((CONVERT(nvarchar(max), [o].[OrderDate]) LIKE N'%1997%') OR (CONVERT(nvarchar(max), [o].[OrderDate]) LIKE N'%1998%'))");
}
The Convert_ToBoolean doesn't test against Convert.ToBoolean(Convert.ToString(x)) translating to CONVERT(bit, CONVERT(nvarchar(max), x))
@MaRK0960 the issue is that string representations of booleans has lots of options (true/false/TRUE/FALSE/1/0?), and these aren't the same across C# and the database. I think it makes sense to leave out bool.TryParse specifically here.
Activity
ErikEJ commentedon Jun 21, 2022
You are often forced to use the CultureInfo overload by various Analyzers
roji commentedon Jun 21, 2022
Yeah, hopefully One Day(TM) we'll have infra for identifying code inside EF Core expression trees, and then we'd be able to suppress those warnings. This is similar to various string methods, null-ref warnings #21663, etc. - added a note under #22086.
MaRK0960 commentedon Jun 25, 2022
I'm interested in working on this issue.
I'm planning on creating an SqlServerParseTranslator similar to SqlServerConvertTranslator.
https://github.com/dotnet/efcore/blob/781ca2451d0d408813acebe87f2fcaa03d4b62e2/src/EFCore.SqlServer/Query/Internal/SqlServerConvertTranslator.cs
But the
IEnumerable<MethodInfo> SupportedMethodswill be the x.Parse methods with one overload.Regarding the tests cases, those are the ones I managed to find:
efcore/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServerTest.cs
Lines 1285 to 1619 in 781ca24
The
Convert_ToBooleandoesn't test againstConvert.ToBoolean(Convert.ToString(x))translating toCONVERT(bit, CONVERT(nvarchar(max), x))Is there a reason for that?
roji commentedon Jun 27, 2022
@MaRK0960 the issue is that string representations of booleans has lots of options (true/false/TRUE/FALSE/1/0?), and these aren't the same across C# and the database. I think it makes sense to leave out bool.TryParse specifically here.
SqlServer: Translate x.Parse (dotnet#28337)