Limit results for specific AutoQuery Data DTO

I have two AutoQuery Data Request DTOs that return the same type:

    [Route("/users/windows/search", "GET", Summary = "Search users")]
    public class SearchWindowsUsers : QueryData<WindowsUser>
    {
        
    }

    [QueryData(QueryTerm.Or)]
    [Route("/users/windows/suggest", "GET", Summary = "Windows user Autosuggest")]
    public class SuggestWindowsUsers : QueryData<WindowsUser>
    {
        public string FirstName { get; set; }
        public string UserName { get; set; }
        public string LastName { get; set; }
    }

These get wired up in Global.asx:

Plugins.Add(new AutoQueryDataFeature {MaxLimit = 100}
                    .AddDataSource(ctx => ctx.ServiceSource<WindowsUser>(new GetWindowsUsers(), HostContext.Cache,
                        TimeSpan.FromMinutes(5)))
//Additional AddDataSources below

Is there a way to override the Max Limit I set for my AQD sources for SuggestWindowsUsers?

You could create a custom AutoQuery implementation or it may be easier to use a QueryFilter, e.g:

Plugins.Add(new AutoQueryDataFeature { MaxLimit = 100 }
    .RegisterQueryFilter<SuggestWindowsUsers, WindowsUser>((req, q, dto) =>
        q.Take(200)
  )
);
1 Like

Did you mean:

.RegisterQueryFilter<SuggestWindowsUsers>((query, dto, request) => query.Limit(dto.Take,10)));

(assuming I wanted fewer than the default)

If you want fewer than the MaxLimit, it’s easier to specify it on the queryString, e.g. ?Take=10.

Note: the API for Limit is Limit(skip,take).