-
-
Notifications
You must be signed in to change notification settings - Fork 158
Dynamic or Computed Filters #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Creating a naive implementation that supports the following: public class FooEvent : Identifiable {
[DynamicFilter("was-active-on")]
public bool WasActiveOn(DateTime date) => (date > StartedAt && date < EndedAt)
} Seems simple but it may be properly translated by EF. However, this opens up the possibility for much more complex queries (i.e. anything can go in the Perhaps it would make more sense to offer some access to the interface IEntityFilter<TEntity> {
IQueryable<TEntity> Filter(IQueryable<TEntity> entities, FilterQuery filterQuery);
} This would allow more obvious implementations (less hiding of the fact that this is being passed to EF), through DI: public class DefaultEntityFilter<TEntity> : IEntityFilter<TEntity> { /* ... */ }
public class FooFilter : DefaultEntityFilter<Foo> {
public IQueryable<Foo> Filter(IQueryable<Foo> foos, FilterQuery filterQuery) {
if(string.Equals(filterQuery.Attribute, "was-active-on", StringComparison.OrdinalIgnoreCase))
return FilterWasActiveOn(foos, filterQuery);
return base.Filter(foos, filterQuery);
}
// ...
} |
This should be resolved by JsonApiDotNetCore/src/JsonApiDotNetCore/Models/ResourceDefinition.cs Lines 123 to 156 in 2221d57
|
A dynamic/computed filter can be defined based on a provided value:
Requirements:
Design/Random Thoughts:
TResource
)?how to communicate the negative impact on application performance? i.e. EF will probably have to load all resources into memory and then apply the filter
The text was updated successfully, but these errors were encountered: