You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we wouldn't group the OR filters the AND will take precedence, SqlKata has the mechanism to generate the above query perfectly well
new Query("Table1").Where(q => q.Or().Where("Column1",10).Or().Where("Column2",20)).Where("Column3",30);
My question is regarding the same functionality but with a HAVING clause, I understood that the API will be the same, but when trying the following code
new Query("Table1").Having(q => q.Or().HavingRaw("SUM([Column1]) = ?",10).Or().HavingRaw("SUM([Column2]) = ?",20)).HavingRaw("SUM([Column3]) = ?",30);
This is the generated SQL
SELECT*FROM"Table1"HAVINGANDSUM("Column3")
The filters within the filter group .Having(q => q...) is missing and the HAVING clause just starts with an AND
Sample test methods
using SqlKata.Compilers;using SqlKata.Tests.Infrastructure;using Xunit;namespace SqlKata.Tests
{publicclassWhereTests:TestSupport{[Fact]publicvoidGroupedWhereFilters(){varq=new Query("Table1").Where(q => q.Or().Where("Column1",10).Or().Where("Column2",20)).Where("Column3",30);varc= Compile(q);
Assert.Equal(@"SELECT * FROM ""Table1"" WHERE (""Column1"" = 10 OR ""Column2"" = 20) AND ""Column3"" = 30", c[EngineCodes.PostgreSql]);}[Fact]publicvoidGroupedHavingFilters(){varq=new Query("Table1").Having(q => q.Or().HavingRaw("SUM([Column1]) = ?",10).Or().HavingRaw("SUM([Column2]) = ?",20)).HavingRaw("SUM([Column3]) = ?",30);varc= Compile(q);
Assert.Equal(@"SELECT * FROM ""Table1"" HAVING (SUM(""Column1"") = 10 OR SUM(""Column2"") = 20) AND SUM(""Column3"") = 30", c[EngineCodes.PostgreSql]);}}}
The text was updated successfully, but these errors were encountered:
@ahmad-moussawi
I'm pleased that I was able to help out an solving this issue, just wondering how your release cycle goes as in to when I can expect to see this fix in the nuget package.
Thanks
Hi,
When using
WHERE
filters we might want to group some filters together, using the following filter as an exampleIf we wouldn't group the
OR
filters theAND
will take precedence, SqlKata has the mechanism to generate the above query perfectly wellMy question is regarding the same functionality but with a
HAVING
clause, I understood that the API will be the same, but when trying the following codeThis is the generated SQL
The filters within the filter group
.Having(q => q...)
is missing and theHAVING
clause just starts with anAND
Sample test methods
The text was updated successfully, but these errors were encountered: