Skip to content

Cannot wrap filter in parenthesis #132

Description

@Axemasta

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();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions