Skip to content

Increase ResourceDefinition GetFilterQuery Flexibility #482

Closed
@joshhubers

Description

@joshhubers

I really like the new ResourceDefinition interface, and it has allowed me to really separate and clean out some of the manual filtering I was doing traditionally in my EntityRepositories. That said, I do have a hitch with the following line:

return defaultQueryFilter(entities, filterQuery.Value);

Is there are particular reason why the delegate takes only the filterQuery.Value and not the whole FilterQuery object (or at least value and operation)?

While the new ResourceDefintion has cleared up the basic filtering logic I have, I still have to keep messy logic for specific FilterQuery.Operation's.

public class FooRepository : DefaultEntityRepository<Foo>
...
public override IQueryable<Foo> Filter(IQueryable<Foo> foos, FilterQuery filterQuery)
{
  if(filterQuery.Operation == "in" && filterQuery.Attribute == "bar")
    return someInFilter(filterQuery.Value);
}
...

The new QueryFilter alias would then be something like:

public class QueryFilters : Dictionary<string, Func<IQueryable<T>, string, string, IQueryable<T>>> { }

or

public class QueryFilters : Dictionary<string, Func<IQueryable<T>, FilterQuery, IQueryable<T>>> { }

Such that in the ResourceDefinition GetQueryFilters you can also know the filter operation being used on the values provided.

I would be glad to get thoughts on this and eventually open a PR for this.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions