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

Calling Filter multiple times with useParenthesis produces unexpected results #97

Open
crackalak opened this issue May 6, 2022 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@crackalak
Copy link

crackalak commented May 6, 2022

class Test
{
    public string Name { get; set; }
    public string Description { get; set; }
    public int Value { get; set; }
}
var query1 = queryBuilder.For<Test>("mock")
                         .ByList()
                         .Filter((x, f, o) => (x.Name == "name" || x.Description == "description") && x.Value == 1, useParenthesis: true);
var items1 = query1.ToDictionary();
var filter1 = items1["$filter"];

Output (Correct): (Name eq 'name' or Description eq 'description') and Value eq 1

var query2 = queryBuilder.For<Test>("mock")
                         .ByList()
                         .Filter((x, f, o) => (x.Name == "name" || x.Description == "description"), useParenthesis: true);
query2 = query2.Filter((x, f, o) => x.Value == 1, useParenthesis: true);
var items2 = query2.ToDictionary();
var filter2 = items2["$filter"];

Output (Incorrect): Name eq 'name' or Description eq 'description' and Value eq 1

I would expect both outputs to match, should this not be the case?

@ZEXSM ZEXSM added the bug Something isn't working label May 6, 2022
@ZEXSM ZEXSM added this to the v3.0.0 milestone May 6, 2022
@amorelIM
Copy link

amorelIM commented Aug 3, 2023

I'm a bit late, but I found a way to patch the problem while waiting for real fix. It can be done by placing a "true" in front of your conditions.

var query2 = queryBuilder.For<Test>("mock")
                         .ByList()
                         .Filter((x, f, o) => true && (x.Name == "name" || x.Description == "description"), useParenthesis: true);
query2 = query2.Filter((x, f, o) => x.Value == 1, useParenthesis: true);

var items2 = query2.ToDictionary();

var filter2 = items2["$filter"];

@ronaldoasilva
Copy link

I'm a bit late, but I found a way to patch the problem while waiting for real fix. It can be done by placing a "true" in front of your conditions.

var query2 = queryBuilder.For<Test>("mock")
                         .ByList()
                         .Filter((x, f, o) => true && (x.Name == "name" || x.Description == "description"), useParenthesis: true);
query2 = query2.Filter((x, f, o) => x.Value == 1, useParenthesis: true);

var items2 = query2.ToDictionary();

var filter2 = items2["$filter"];

it worked for me, tthanks man :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants