Skip to content
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

Cannot wrap filter in parenthesis #132

Open
Axemasta opened this issue Dec 10, 2024 · 0 comments
Open

Cannot wrap filter in parenthesis #132

Axemasta opened this issue Dec 10, 2024 · 0 comments

Comments

@Axemasta
Copy link

Axemasta commented Dec 10, 2024

I have the following odata query written by hand & working in postman:
$filter=ResourceId eq 73 and (CreatedDate gt 2024-11-29T00:00:00Z or ClosedDate gt 2024-11-29T00:00:00Z or TimeLockChanged gt 2024-11-29T00:00:00Z or SignoffTime gt 2024-11-29T00:00:00Z)

so the query I want to build with is a match on a resource id, anything that matches a number of conditions based on a given date.

The best I've been able to come up in code is:

var filterQuery = new ODataQueryBuilder<MyResource>()
	.For<MyResource>(x => x.ResourceId)
	.ByList()
	.Filter((x, f, o) => x.ResourceId == resourceId)
	.Filter((x, f, o) => (x.CreatedDate > changedDate || x.ClosedDate > changedDate || x.SignoffTime > changedDate || x.TimeLockChanged > changedDate), useParenthesis: true)
	.OrderByDescending(x => x.CreatedDate)
	.ToDictionary();

The resource id matches however the grouped clause doesn't generate as expected,
expected:
(CreatedDate gt 2024-11-29T00:00:00Z or ClosedDate gt 2024-11-29T00:00:00Z or TimeLockChanged gt 2024-11-29T00:00:00Z or SignoffTime gt 2024-11-29T00:00:00Z)

actual:
((CreatedDate gt 2024-11-29T00:00:00Z or ClosedDate gt 2024-11-29T00:00:00Z) or SignoffTime gt 2024-11-29T00:00:00Z) or TimeLockChanged gt 2024-11-29T00:00:00Z

Also to note if I group the queries in the same filter, the result output is the same:

var filterQuery = new ODataQueryBuilder<MyResource>()
	.For<MyResource>(x => x.ResourceId)
	.ByList()
	.Filter((x, f, o) =>
		x.LogbookId == logbookId
		&& (x.CreatedDate > changedDate || x.ClosedDate > changedDate || x.SignoffTime > changedDate || x.TimeLockChanged > changedDate), useParenthesis: true)
	.OrderByDescending(x => x.CreatedDate)
	.ToDictionary();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant