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
1.) In the Linq below only two of the AND clauses are grouped with parenthesis however the generated SQL nests each AND clause (except the last one for unknown reasons). I can't say this will generate incorrect results however it does make the query much more difficult to read and use for debugging purposes. Is this the expected behavior?
2.) The lookups using the string arrays are ignored. The expected SQL is something like ...CASE WHEN left(substring(rn.nativeaddress, 8, LEN(rn.nativeaddress) - 8), CHARINDEX('.', substring(rn.nativeaddress, 8, LEN(rn.nativeaddress) - 8))- 1) IN ('64','65','66','67','68','69','70','71','72','73','74','75','76','77','78','79') THEN 'Vendor1'.... I can't make sense of the generated SQL. Arguably this lookup can be done client side but it's a bit more efficient for me I can just get back a ready-to-use object from the server.
If either of these questions warrant further investigation please let me know and I will put together a runnable example to reproduce it.
DECLARE @__now_Date_0 datetime = '2021-10-11T00:00:00.000';
SELECT [o].[JobKey], [i].[StartTime], [o].[CellRelayId], [n].[SerialNumber], [r].[NativeAddress], [o].[MCHInstanceId], CASE
WHEN CASE
WHEN [r].[NativeAddress] IS NULL OR ([r].[NativeAddress] = '') THEN NULL
ELSE SUBSTRING([r].[NativeAddress], 8 + 1, CAST(LEN([r].[NativeAddress]) AS int) - 8)
END IS NULL OR ((CASE
WHEN [r].[NativeAddress] IS NULL OR ([r].[NativeAddress] = '') THEN NULL
ELSE SUBSTRING([r].[NativeAddress], 8 + 1, CAST(LEN([r].[NativeAddress]) AS int) - 8)
END = '') AND CASE
WHEN [r].[NativeAddress] IS NULL OR ([r].[NativeAddress] = '') THEN NULL
ELSE SUBSTRING([r].[NativeAddress], 8 + 1, CAST(LEN([r].[NativeAddress]) AS int) - 8)
END IS NOT NULL) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END, CASE
WHEN [r].[NativeAddress] IS NULL OR ([r].[NativeAddress] = '') THEN NULL
ELSE SUBSTRING([r].[NativeAddress], 8 + 1, CAST(LEN([r].[NativeAddress]) AS int) - 8)
END, [o].[TotalEndpoints], [o].[TotalEndpoints] - [o].[SuccessfulEndpoints]
FROM [Analytics].[OwceCommRates] AS [o]
INNER JOIN [OWCE].[InterrogationJob] AS [i] ON CAST([o].[JobKey] AS numeric(9,0)) = [i].[JobKey]
INNER JOIN [OWCE].[RelayNode] AS [r] ON [o].[CellRelayId] = [r].[CellRelayId]
LEFT JOIN [OWCE].[Node] AS [n] ON [r].[NodeKey] = CAST([n].[RelayNodeKey] AS numeric(9,0))
WHERE ((((((([n].[NodeKey] IS NOT NULL
AND (CONVERT(date, [i].[SubmittedTime]) > @__now_Date_0))
AND (DATEPART(hour, [i].[SubmittedTime]) < 12))
AND ([i].[JobStatus] = 'W'))
AND (([o].[TotalEndpoints] - [o].[SuccessfulEndpoints]) > 0))
AND ([o].[CellRelayId] > 0)) AND [r].[SerialNumber] NOT IN (N'11', N'53098'))
AND ([n].[HardwareVersion] IN (1.0, 3.0, 0.0) OR (CONVERT(int, [n].[SerialNumber]) > 9999999)))
AND ([n].[Registered] = 1.0)
Versions
.net core 5.0
EF Core 5.0.8
The text was updated successfully, but these errors were encountered:
This is just due to construction of expression tree by compiler into BinaryExpression. It is a binary tree so nesting will come which requires to put parenthesis to preserve operator precedence. The result should be same regardless.
The lookup should translate to server, need to investigate why it isn't. A repro would be useful.
Questions
1.) In the Linq below only two of the AND clauses are grouped with parenthesis however the generated SQL nests each AND clause (except the last one for unknown reasons). I can't say this will generate incorrect results however it does make the query much more difficult to read and use for debugging purposes. Is this the expected behavior?
2.) The lookups using the string arrays are ignored. The expected SQL is something like
...CASE WHEN left(substring(rn.nativeaddress, 8, LEN(rn.nativeaddress) - 8), CHARINDEX('.', substring(rn.nativeaddress, 8, LEN(rn.nativeaddress) - 8))- 1) IN ('64','65','66','67','68','69','70','71','72','73','74','75','76','77','78','79') THEN 'Vendor1'...
. I can't make sense of the generated SQL. Arguably this lookup can be done client side but it's a bit more efficient for me I can just get back a ready-to-use object from the server.If either of these questions warrant further investigation please let me know and I will put together a runnable example to reproduce it.
Thanks.
Linq
Generated SQL
Versions
.net core 5.0
EF Core 5.0.8
The text was updated successfully, but these errors were encountered: