-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Composite search filter can not search for Enums. #58
Comments
System.ArgumentException: Method 'Boolean Contains(System.String)' declared on type 'System.String' cannot be called with instance of type 'ItPos.DataAccess.Common.Models.User.Institute' |
Institute is a different type than string, so Something like public class StudentInfoShortResponseFilter : PaginationFilterBase
{
[CompareTo(nameof(StudentInfoShortResponse.FullName),
nameof(StudentInfoShortResponse.AcademicGroup),
nameof(StudentInfoShortResponse.StudentIdCard),
"Institute.Name")]
[StringFilterOptions(StringFilterOption.Contains)]
[ToLowerContainsComparison]
public string? Search { get; set; }
} |
Oh, sorry, I missed that Institute is an enum. Enums are numeric fields and stored as numeric value types in databases by default. If you want to compare strings to enums, you should project enum values as string value in a different field and filter that field with autofilterer. That projection might be done with myDataSource.Select(x => new MyProjectedResult
{
FullName = x.FullName,
AcademicGroup = x. AcademicGroup,
StudentIdCard = x. StudentIdCard,
InstituteName = x.Institute?.ToString()
}).ApplyFilter(...) And you can use InstituteName string field for filtering: Something like public class StudentInfoShortResponseFilter : PaginationFilterBase
{
[CompareTo(nameof(StudentInfoShortResponse.FullName),
nameof(StudentInfoShortResponse.AcademicGroup),
nameof(StudentInfoShortResponse.StudentIdCard),
"InstituteName")] // 👈 here
[StringFilterOptions(StringFilterOption.Contains)]
[ToLowerContainsComparison]
public string? Search { get; set; }
} |
It says then that it can not do query with toString(), like not supported, but I'm using mapster, so Idk. |
Thanks for the your answer btw! public Institute? Institute {get;set;} But not via CompareToAttribute - it's strange thing. |
When you see that a separate field is working, there is a feeling that the complex variable will also work. I would consider this as a possible vector for improving your solution. If I have the time/opportunity, I will take a look and try to come up with a solution. |
I have such filter:
And when I'm trying to write in 'search' anything - it always gives me all records, not filtering it.
StudentInfoShortResponse.Institute - enum type.
If I'll delete this from attribute - it will search for other properties.
With such enum property in filter attribute it stops write filter in query.
If I'll write
in filter - all will be fine too.
The text was updated successfully, but these errors were encountered: