Open jasonycw opened 5 years ago
Further info: The exception is thrown from here
Sieve.dll!Sieve.Services.SievePropertyMapper.FindProperty<
The class name
>(bool canSortRequired, bool canFilterRequired, string name, bool isCaseSensitive)
Sieve.Exceptions.SieveMethodNotFoundException: 'roles not found.'
May be you need add "ISieveCustomFilterMethods customFilterMethods" to constructor ApplicationSieveProcessor and send this arg to base() construstor. Like this:
public class ApplicationSieveProcessor : SieveProcessor
{
public ApplicationSieveProcessor(
IOptions<SieveOptions> options,
ISieveCustomFilterMethods customFilterMethods)
: base(options, customFilterMethods)
{
}
protected override SievePropertyMapper MapProperties(SievePropertyMapper mapper)
{
mapper.Property<Domain.User.User>(x => x.UserRoles)
.CanFilter();
return mapper;
}
}
And of couse your nead add this service to Startup.cs
services.AddScoped<ISieveCustomFilterMethods, SieveCustomFilterMethods>();
Problem is in that your SieveCustomFilterMethods never instantiated, and sieve didn't know about your new method Roles(IQueryable<Domain.User.User> source, string op, string[] values)
I found that Sieve will flow an error if I try to use CustomFilter and don't add Sieve attributes and no CustomSieveProcessor
e.g. I got this custom filter
And this UserClass
If I don't add
[Sieve(CanFilter=true)]
to theUser.UserRoles
, and call the API with?filters=roles==admin
The return result will be filter with UserRoles that contain "Admin"BUT!
processor.Apply
will keep throwing the following exception without breaking the filterThen I tried adding a custom SieveProcessor while keeping my custom filter
Then, calling
?filters=roles==admin
will cause another exception that break the filterIf I change the
MapProperties
toThis will not trigger any filter at all.
Is there a way to keep CustomFilter while adding FluentAPI properly?