feat: Implement field-to-field comparison in filter expressions#328
feat: Implement field-to-field comparison in filter expressions#328
Conversation
Co-authored-by: alirezanet <7004080+alirezanet@users.noreply.github.com>
alirezanet
left a comment
There was a problem hiding this comment.
Looks good but we need some additional changes:
- make sure to add some integration test with EntityFramework so we make sure it also works in ORMs.
- add some tests to cover complex scenarios with grouping. Gridify uses parenthesis for group a set of conditions together. I want to make sure this feature doesn't create any conflicts with the existing behavior.
- we should also support and test this feature with the QueryBuilder class, as you know we have to ways of creating queries in Gridify. the extension methods and the QueryBuilder.
- You should also update the documentation in the relevant pages.
All addressed in
|
alirezanet
left a comment
There was a problem hiding this comment.
add one more test to make sure escaping works.
so user should be able to search for this value if needed for example:
field=\(somevalue\)
field=\(somevalue
field=somevalue\)
field=some\(value
… configuration entry Co-authored-by: alirezanet <7004080+alirezanet@users.noreply.github.com>
Added |
Adds support for comparing two mapped fields against each other in filter expressions using
(fieldName)syntax on the right-hand side of any operator. Feature is opt-in via configuration to avoid breaking changes.Syntax
Changes
Parser / Syntax
FieldReferenceExpressiontoSyntaxKindFieldReferenceExpressionSyntaxnode wraps aFieldExpressionSyntaxfor the(fieldName)RHS patternParseRightHandExpression()(renamed fromParseValueExpression) detectsOpenParenthesisToken → FieldTokensequence after an operator and returns aFieldReferenceExpressionSyntaxinstead of a value nodeQuery Builder
BaseQueryBuilder.BuildQueryFromBinaryExpression()routesfield op (field)patterns to newConvertFieldToFieldQuery()methodBuildFieldToFieldQuery()added as avirtualmethod (throws by default, so non-LINQ builders like Elasticsearch remain unaffected)LinqQueryBuilderimplements two cases:Selectlambdas, unifies inner parameters, buildsAny(predicate)expression=*,!*,^,!^,$,!$for string field comparisonsConfiguration
GridifyGlobalConfiguration.AllowFieldToFieldComparison— global opt-in (default:false)GridifyMapperConfiguration.AllowFieldToFieldComparison— per-mapper opt-in, inherits global defaultTesting
QueryBuilderintegrationEscapedParenthesesInValue_ShouldBeSearchedAsLiteralValuetheory test covering all escape patterns (\(value\),\(value,value\),value\(middle,value\)middle) to ensure escaping still works correctly when the feature is enabledEntityFrameworkSqlProviderIntegrationTests) confirming valid SQL generation for both simple and nested collection field-to-field comparisonsDocumentation
docs/pages/guide/filtering.md: new "Field-to-Field Comparison" section with enabling instructions, syntax reference, and practical examples (including combining with logical operators and grouping)docs/pages/guide/gridifyGlobalConfiguration.md: newAllowFieldToFieldComparisonglobal configuration entrydocs/pages/guide/gridifyMapper.md: newAllowFieldToFieldComparisonper-mapper configuration entry underGridifyMapperConfigurationType of change
Checklist
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.