Open nielslucas opened 1 year ago
Everything worked fine in 2.3.7*
SqlKata: v.2.4.0 SqlServerCompiler
Same with my issue. The following query gives me a wrong result:
var query = new SqlKata.Query("Customer")
.Distinct()
.Select("Name")
.Where("Name", "John")
.ForPage(2, 10);
The result is:
SELECT DISTINCT [Name]
FROM [Customer]
ORDER BY (SELECT 0) OFFSET 10 ROWS FETCH NEXT 20 ROWS ONLY
The query is wrong and sql server throws the following error:
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
Workaround. In order to avoid such errors I have switched UseLegacyPagination = true
. You can also use GroupBy
instead.
Query:
Result:
The Order By is added with a 'SELECT 0' which is invalid. I added myself a .OrderBy and everything works fine. In 3.7 this worked fine.