querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

Where with bool or bool? is compiled as "true" or "false" rather than "0" or "1"

Open benmccallum opened this issue 4 years ago • 4 comments

Repro Go here: https://sqlkata.com/playground/sqlserver Paste this:

bool? lol = true;
bool lol2 = true;
var query = new Query("Users").Where("lol", lol).Where("lol2", lol2);

SQL Server doesn't support true/false, only 0 or 1

benmccallum avatar Jun 25 '20 15:06 benmccallum

Hmm, I believe maybe we're suppose to use WhereTrue or WhereFalse... Not 100% clear though. Could do with an example on the Where page of docs.

benmccallum avatar Jun 25 '20 15:06 benmccallum

I swear I've had this working before though... Could you confirm if it's a bug or not?

benmccallum avatar Jun 25 '20 15:06 benmccallum

A workaround is to do a sneaky Convert.ToInt16(lol) in there, but this is a bit of a nasty regression if that's what it is. Could bite a lot of people.

benmccallum avatar Jun 25 '20 15:06 benmccallum

Maybe there could be a .WhereBooleanIs(true/false) extension method?

benmccallum avatar Jul 08 '20 13:07 benmccallum

I think this was solved by #510 check https://sqlkata.com/release/v2.3.8#whereboolean-is-now-identical-to-wheretrue-and-wherefalse So it can be closed now

ahmad-moussawi avatar Oct 02 '22 09:10 ahmad-moussawi