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

Example of query that works in SQLite but not SQL Server: An expression of non-boolean type specified... #476

Open
rjpowers10 opened this issue Feb 10, 2023 · 2 comments

Comments

@rjpowers10
Copy link

I wrote the following query in my Orchard Core site (omitting some details for brevity)

// 'published' is a boolean method parameter
query.With<ContentItemIndex>(c => (published && c.Published) || (!published && c.Latest))

This generates the following clause. For simplicity I've replaced the parameters with literal values, and in this example the value of published is true so it is replaced by a 1.

(1 and ([ContentItemIndex_a1].[Published] = 1)) or (0 and ([ContentItemIndex_a1].[Latest] = 1)

This clause is valid in SQLite but not in SQL Server. SQL Server will complain that "An expression of non-boolean type specified in a context where a condition is expected, near 'and'."

To make SQL Server happy I think something like the following clause should be generated.

(1 = 1 and ([ContentItemIndex_a1].[Published] = 1)) or (0 = 1 and ([ContentItemIndex_a1].[Latest] = 1)

It was easy enough for me to rewrite my query to avoid the problem as a workaround.

@hishamco
Copy link
Contributor

Could you please write a unit test for similar case, to ensure it's fail?

@rjpowers10
Copy link
Author

Could you please write a unit test for similar case, to ensure it's fail?

I can try but I'm not sure how I would write it. I can take a look at some other tests for inspiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants