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

Query: runtime error (invalid cast) for query projecting bool property with conditional and coalesce #12958

Closed
maumar opened this issue Aug 9, 2018 · 0 comments
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-3.0 type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Aug 9, 2018

query:

ctx.Gears.Select(g => g.LeaderNickname != null ? (bool?)(g.Nickname.Length == 5) ?? default(bool) : (bool?)null)

query:

SELECT CASE
   WHEN [g].[LeaderNickname] IS NOT NULL
   THEN COALESCE(CASE
	   WHEN CAST(LEN([g].[Nickname]) AS int) = 5
	   THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT)
   END, 0) ELSE NULL
END
FROM [Gears] AS [g]
WHERE [g].[Discriminator] IN (N'Officer', N'Gear')

exception:

Specified cast is not valid.

we should inject cast to bool around the coalesce inside the case statement

@ajcvickers ajcvickers added this to the 3.0.0 milestone Aug 10, 2018
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jun 28, 2019
@smitpatel smitpatel assigned smitpatel and unassigned maumar Dec 10, 2019
@smitpatel smitpatel added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed add-regression-test try-on-latest labels Dec 10, 2019
@smitpatel smitpatel modified the milestones: Backlog, 3.1.0 Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-3.0 type-bug
Projects
None yet
Development

No branches or pull requests

3 participants