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

Building the filter #50

Open MohammedNagar opened 5 years ago

MohammedNagar commented 5 years ago

Thanks a lot for this project, It's so special.

My issue is about (How to use). I'm a little confused, I have read the documentation and the code-project explanation, but I still miss something.

How could I compose the following code from the UI?

var filter = new Filter(); filter.By("Id", Operation.Between, 2, 4, Connector.And); filter.By("Contacts[Value]", Operation.EndsWith, "@email.com", default(string), Connector.And); filter.By("Birth.Country", Operation.IsNotNull, default(string), default(string), Connector.Or); filter.By("Name", Operation.Contains, " John");

I want the end user to build the previous query(filter) first(not me) then converted to equivalent lambda expression after that. I'll be grateful if there's some example to explain this point more.

aldrashan commented 5 years ago

I'm not entirely sure what you mean. You want to create filters in your UI and pass them to the backend and convert these to the correct lambda filter?

In our case we use QueryBuilder. These filter values get posted to the backend and parsed to C# objects. I then wrote a function that recursively creates the correct lambda filter by converting the parsed filter tree to my needed lambda filter tree.

Either way you're going to need to pass your filters to the backend and write a function that converts them to the query you need by evaluating the passed filter values.

dmitribodiu commented 5 years ago

I then wrote a function that recursively creates the correct lambda filter by converting the parsed filter tree to my needed lambda filter tree.

@aldrashan Can you point me where is that function located please?