sqlkata / querybuilder

SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
https://sqlkata.com
MIT License
3.09k stars 498 forks source link

Query.Not() doesn't apply to WhereRaw #598

Closed SunnyC17 closed 2 years ago

SunnyC17 commented 2 years ago

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'
ahmad-moussawi commented 2 years ago

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

SunnyC17 commented 2 years ago

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