Open radeanurazvan opened 6 years ago
` mapper.Property
mapper.Property
You can try this,
Just don't configure the FirstName and LastName properties for sieve..
Create two (first/last name) or one (full name) custom filters, sieve will call that as it won't find that property on entity definition.
Hello,
I started using Sieve library a few days ago but I encountered some problems when working with objects / nested values as filter subjects. For instance, consider the following configuration in the FluentApi:
The names are being specified for the FullName and PhoneNumber just for consistency when querying from the client. There are no custom filter methods defined for that entity. Here is how the FirstName, LastName and PhoneNumber properties are defined:
The Name value object:
The PhoneNumber is just another ValueObject which contains phone numbers specific domain logic. The point here is that my domain entity (BackOfficeUser) is modeled using value objects, which are concrete types defined by me, yet not primitive types like string (as Sieve is expecting). So the problems that I encounter are:
2.Sieve fails when converting string value from SieveModel to my Name type. This could be solved if I define a cast operator in my Name class, but I really don't want to do that since I want to enforce this Value Object to always have a valid state, hence a cast from any string would violate this.
But as you have seen, the value objects described above have a "Value" property which is a string. So I may use it for filtering, right? So my second though was this:
But this fails when Sieve tries to evaluate the property given in the expression at filter time. It fails with an error like "Property 'Value' is not part of type {NameSpace}.BackOfficeUser". It fails because I'm using nested values instead of direct usage.
What I've considered: I considered creating separate filter methods for these value objects, but it doesn't work since they are part of the model and not entities as a whole. I tried to create generic custom filter methods, like :
But this doesn't get recognized by Sieve when looking for custom filter methods for the fiven
Possible solutions: 1) Support nested values. At least the second approach should be doable. Getting the nested value at filter time shouldn't be hard. 2) Expose a new FluentApi method. What about this:
I think this problem also occurs when trying to sort complex objects / nested values. It would be nice if Sieve could support that.