cbaker
March 18, 2019, 4:33pm
1
AutoQuery set to
new AutoQueryFeature
{
MaxLimit = 100
}
RequestDto
var findReportRequest = new FindReportRequest
{
Fields = $“distinct {fieldName}”
};
SQL Exception thrown
Basically the sql produced with ordering the select statement
ORDER BY “Table”.“Id” OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY
I can make the request work by removing the MaxLimit.
Is it possible to both the MaxLimit set and get distinct lists of field values?
mythz
March 18, 2019, 4:46pm
2
Looks like you’ve hit a limitation of SQL Server where it needs any OrderBy fields to appear in the select list.
You can either specify your own OrderBy
or OrderByDesc
(of the distinct field) or disable implicit ordering for paged queries with:
Plugins.Add(new AutoQueryFeature {
OrderByPrimaryKeyOnPagedQuery = false
})
But that would reduce the predictability of paged query results.
cbaker
March 18, 2019, 5:29pm
3
I changed the settings to include
OrderByPrimaryKeyOnPagedQuery = false
It didn’t change the SQL issued. The order by clause is still being included in the sql.
mythz
March 18, 2019, 6:57pm
4
Are you sure, It only adds it if it’s enabled:
{
var fieldNames = dto.OrderBy.Split(FieldSeperators, StringSplitOptions.RemoveEmptyEntries);
q.OrderByFields(fieldNames);
}
else if (dto.OrderByDesc != null)
{
var fieldNames = dto.OrderByDesc.Split(FieldSeperators, StringSplitOptions.RemoveEmptyEntries);
q.OrderByFieldsDescending(fieldNames);
}
else if ((dto.Skip != null || dto.Take != null)
&& (options != null && options.OrderByPrimaryKeyOnLimitQuery))
{
q.OrderByFields(typeof(From).GetModelMetadata().PrimaryKey);
}
}
private static void AppendJoins(SqlExpression<From> q, IQueryDb dto)
{
if (dto is IJoin)
{
var dtoInterfaces = dto.GetType().GetInterfaces();
It would also be the last thing I’d change, did you try changing the OrderBy?:
var findReportRequest = new FindReportRequest {
Fields = $$"distinct {fieldName}",
OrderBy = fieldName
};
cbaker
March 18, 2019, 7:28pm
5
I didn’t try the OrderBy setting directly. I tried the suggestion and it worked.
On the OrderByPrimaryKeyOnPagedQuery = false
Pretty sure, I’m doing this;
new AutoQueryFeature
{
MaxLimit = 100,
OrderByPrimaryKeyOnPagedQuery = false
}
The MaxLimit is being respected.
Now I have a work around though, I’m good. Thanks for your help!