sqlkata/querybuilder

Query.Not() doesn't apply to WhereRaw

SunnyC17 opened this issue · 2 comments

When I am using Not(), the WhereRaw clause is not negated. I have to use WhereRaw instead of Where in my use case so would there be a fix to this issue? Suggestions for work-around will also be appreciated.

var query = new Query("Posts").Not();
query = query.WhereRaw("lower(Title) = ?", "sql");

returns

SELECT
  *
FROM
  [Posts]
WHERE
  lower(Title) = 'sql'

Yes this intended, and should be mentioned in the doc, why not negating directly your expression?
as a workaround you can nest your condition with

`WhereNot(q => q.WhereRaw("A = B"))

check
https://sqlkata.com/playground?code=var%20query%20%3D%20new%20Query(%22A%22).WhereNot(q%20%3D%3E%20q.WhereRaw(%22A%20%3D%20B%22

Thanks for the workaround, the issue at my end has been resolved.