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
Extend Filter function with cross-record boolean logic #38
Comments
I think using the if not, please provide your expected LINQ query for Example3. |
It's not strictly OR since both values must be true. The nearest LINQ I can think of at the moment is
but really I am trying to evaluate if both Not sure if it's possible. That's why I don't think it's a FilterExpression but a new feature such as LogicExpression where certain rules can be appended and determined if true/false. |
according to your example if we use OR the problem can be solved easily: var query3 = new GridifyQuery() { Filter = "(Rank=1,Val1<5) | (Rank=2,Val1>5)" };
var expression3 = query3.GetFilteringExpression(gridifyMapper).Compile();
var HasAny = array.Any(expression3); // get bool result from query
var Count = array.Count(expression3); // count the results the thing is expressions are not only a filtering operation, you can use an expression to do whatever you want.
also, as you said before (there cannot be any records that are ranked both 1 and 2) so we can not use AND between our two conditions here. I am confused what are you asking |
It doesn't work for filtering as all conditions cannot be met. I was thinking more a boolean condition evaluator, it's close in functionality but outcome is different. Some of this can be evaluated in code but trying to do it just via the Example1:
Example2:
Example3:
|
So if I understood correctly you don't want to get any results back from your array. you just want to evaluate the whole collection to make sure certain conditions passed or not. the problem is unfortunately, this feature doesn't have any general use-case in most applications that's why I don't think adding this to gridify be a good idea. var x = array.Any(a => a.Rank == 1 && a.Val1 < 5) &&
array.Any(a => a.Rank == 2 && a.Val1 > 5); gridify is fully compatible with ORMs and LINQ itself, having this feature breaks this compatibility. I don't close this issue, maybe later someone or I found a solution to have this in a single Linq query. |
You understand correctly. This is a feature suggestion to make a |
Hi, var builder = new QueryBuilder<Level1>()
.AddCondition("Rank=1,Val1<5")
.AddCondition("Rank=2,Val1>5");
var evaluationResult = builder.Evaluate(array); Using a single stringNow because we found a way to evaluate multiple conditions if you want to somehow use a single string you can write your own logic or separator. void AddConditionsToBuilder<T>(string conditions, string seprator, IQueryBuilder < T > builder) =>
conditions.Split(seprator).Select(c => builder.AddCondition(c));
var conditions = "(Rank=1,Val1<5)+(Rank=2,Val1>5)";
var builder = new QueryBuilder<Level1>();
AddConditionsToBuilder(conditions,"+",builder);
var result = builder.Evaluate(array); Using builder to get Filtering expressionI suggest instead of using the mapper and gridifyQuery from now on use the new var compiledExpression = builder.BuildFilteringExpression().Compile(); |
This is brilliant! Thank you so much, this library is excellent. Only have one question... :) Is it possible to compile the QueryBuilder so you get the same performance as the FilteringExpression? |
Thank you,
You still can compile any expression that returns from The output of these methods can be compiled since both returns an Expression.
Also, feel free to give your feedback. |
I hope you don't mind my testing and feedback, you are doing great work here. On the Example1:
Example 2:
Example1: circa 50µs I can't provide any data right now but may get some time next week. |
No, I love feedbacks :). just try to open another issue if it is a different topic or use discussions. in the first example, you are filtering the data in the second one you evaluating conditions, these two are completely different operations. you can compare update: |
Is your feature request related to a problem? Please describe.
Say I have this filter logic,
Filter = "(Rank=1,Val1<5),(Rank=2,Val1>5)"
Assuming no records have the same Rank, this fails as there cannot be any records that are ranked both 1 and 2. However, sometimes we need cross-record logic such as return 1st ranked item but only if 2nd ranked item meets certain criteria.
In the following code, Example1 and Example2 filters both match a record, but Example3 fails as both cannot be satisfied at same time
Describe the solution you'd like
Is it possible to extend functionality to include
BooleanLogicExpression
?Eg something like this where the query returns if all of the filter expressions are true/false?
It similar to chaining as here but trying to apply additional logic outside of a record.
The text was updated successfully, but these errors were encountered: