I want to only allow some properties to be used in OData query $filter option.
I see that there an AllowedOrderByProperties parameter to EnableQueryAttribute, but I didn't find another for $filter. Did I just miss it? If not, what would it take to implement it?
You can try the following:
once you have the builder, you can list the properties of the entitySet then you can mention if the field is filterable or not.
var entityTypeConfig = builder.EntitySet<SomeType>("SomeType").EntityType;
entityTypeConfig.Property(x => x.SomeField);
entityTypeConfig.Property(x => x.SomeField2).IsNotFilterable().IsNonFilterable();
// not sure what is the difference between them
and in the controller action (the httpGet for example) add
options.Filter.Validate(allowedOptions);
in case a field is not filterable this would throw an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With