dbelmont / ExpressionBuilder

A library that provides a simple way to create lambda expressions to filter lists and database queries.
Apache License 2.0
372 stars 105 forks source link

Groups #46

Open madben2000 opened 5 years ago

madben2000 commented 5 years ago

Hey,

there only exists StartGroup() function. How to end a group? How do you build following statement:

a=5 or (a=8 and (b=5 or c=7)) or d=1

Thanks

dbelmont commented 5 years ago

Hi @madben2000,

The EndGroup() doesn't exist because each group is automatically closed upon starting a new one, you just need to move all groups to the end of your expression. And, by the way, there is also no need to use StartGroup() for the very first group because it's automatically created as well. In that sense, your proposed expression should look something like this:

var filter = new Filter<MyType>();
filter.By("a", Operation.EqualTo, 5);
filter.By("d", Operation.EqualTo, 1);
filter.StartGroup();
filter.By("a", Operation.EqualTo, 8);
filter.StartGroup();
filter.By("b", Operation.EqualTo, 5, Connector.Or);
filter.By("c", Operation.EqualTo, 7);

I would ask you to please let me know if that works for you as I wrote the above snippet off the top of my head and didn't test it.

Cheers, David

madben2000 commented 5 years ago

Sorry for my late response. Yes for my expression this would be possible. But what about

(A=1 || (B=2 && F=5)) && (C=3 || D=4)

as asked in #49? I have no idea how to create muliple non-nested groups like

(Group1) && (Group2)...