However, I need to know what the template for ApplyFilter should look like so that only the FK property name is retrieved. I know that %%np-filter-fields%% is wrong, but what would be correct?
When I set the flag on a navigation property in the suite to indicate that it should be Filterable, this is indeed included in the InputDto, but it is then missing from certain methods in the repository. It only exists on GetListWithNavigationPropertiesAsync and GetCountAsync. However, it should also be present on GetListAsync.
I don’t understand why this filtering option shouldn’t also be available on GetListAsync? What I want to filter should surely be independent of whether or not I want the full set of navigation properties in the result.
We very rarely use the methods that load the navigation properties, as they usually load too much data that we don’t actually need. We’d much rather only load the data we actually need. Nevertheless, we still need the option to filter by an ID (e.g. to load all of a customer’s projects, in which case we’d want to filter by customerId).
We’ve already had to customise the Suite templates because we don’t want paged lists by default, so we’ve implemented GetListAsync and GetPagedListAsync. This works perfectly, and we get the methods generated that we need (perhaps this is something you could consider extending).
I wanted to do the same for the filter, but I got stuck at the ApplyFilter() stage. Everything else is now generated correctly using the navigation properties parameters, but how should I construct the query in ApplyFilter() so that the WhereIf is put together correctly?
This are parts of the changed Server.Repository.EfCoreRepository.txt:
public virtual async Task<List<%%entity-name%%>> GetListAsync(
string? filterText = null,
%%dto-field-names-with-type-include-navigation-properties%%%%<if:HasAnyFilterableProperties>%%,%%</if:HasAnyFilterableProperties>%%
string? sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CancellationToken cancellationToken = default)
{
var query = ApplyFilter((await GetQueryableAsync()), filterText%%<if:HasAnyFilterableProperties>%%, %%</if:HasAnyFilterableProperties>%%%%dto-field-names-include-navigations%%);
query = query.OrderBy(string.IsNullOrWhiteSpace(sorting) ? %%entity-name%%Consts.GetDefaultSorting(false) : sorting);
return await query.PageBy(skipCount, maxResultCount).ToListAsync(cancellationToken);
}
protected virtual IQueryable<%%entity-name%%> ApplyFilter(
IQueryable<%%entity-name%%> query,
string? filterText = null%%<if:HasAnyFilterableProperties>%%,%%</if:HasAnyFilterableProperties>%%
%%dto-field-names-with-type-include-navigation-properties%%)
{
return query
%%apply-filter-text%%%%np-filter-fields%%
}
Unfortunately, however, the following line does not produce the result I want:
return query %%apply-filter-text%%%%np-filter-fields%%
This is what is generated (doesn't work because of e.LvKapitel or e.Lv):
protected virtual IQueryable<LvProjektGliederung> ApplyFilter(IQueryable<LvProjektGliederung> query, string? filterText = null, Guid? lvId = null, Guid? lvKapitelId = null)
{
return query.WhereIf(!string.IsNullOrWhiteSpace(filterText), e => true).WhereIf(lvId != null && lvId != Guid.Empty, e => e.Lv != null && e.Lv.Id == lvId).WhereIf(lvKapitelId != null && lvKapitelId != Guid.Empty, e => e.LvKapitel != null && e.LvKapitel.Id == lvKapitelId);
}
And this is what I’d like:
protected virtual IQueryable<LvProjektGliederung> ApplyFilter(IQueryable<LvProjektGliederung> query, string? filterText = null, Guid? lvId = null, Guid? lvKapitelId = null)
{
return query.WhereIf(!string.IsNullOrWhiteSpace(filterText), e => true).WhereIf(lvId != null && lvId != Guid.Empty, e => e.LvId == lvId).WhereIf(lvKapitelId != null && lvKapitelId != Guid.Empty, e => e.LvKapitelId == lvKapitelId);
}
Is there a way to solve this via the template?
Thank you.
Adrian