-
Notifications
You must be signed in to change notification settings - Fork 75
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
Question: Can you get matching results back? #13
Comments
So I just checked in a few changes that should help you out. The MRE creates an Expression Tree but was only exposing a compiled Func. I added a new method that exposes the Expression and allows you to use it against any Linq Provider. Check out the code in this test class https://github.com/runxc1/MicroRuleEngine/blob/master/MicroRuleEngine.Core.Tests/ExpressionToSQLQueryTest.cs |
Thank you for the swift response. Wow! Thank you for exposing the expression. One problem I have, I think, is how I've crafted my rule. Here's an example of a rule that I've created:
As you can see, I am passing the parent object into the rule as an argument and the rules operate against the collection contained therein. If my collection has an entry for TANF alone, or TANF and SNAP or TANF and MED or all three, it will return true. It works surprisingly. Can you think of anyway I can evaluate this rule to get back the rows? Thanks, Michael |
I can't quite say that I follow 100% but I don't see any reason you couldn't get an Expression from that and use it against your collection. Are you trying to do something like the following.
|
Thank you for your response! When I execute the rule, I execute it passing in the parent object, Selection. A Selection object has a collection of Program objects. Each Program object has a Name property. If I go like this... selection.Programs.Where(expression).ToList(); Is there some way that I can execute the expression against the Selection object and get the child objects back? I've used basic LINQ before but this expression tree stuff is very new to me. Thanks, Michael |
Thank you for your help! I found the answer. I took my Selection object and put it in a list. I then executed a .Where() on that list which then evaluated the child objects and returns them. Thank you for adding that ToExpression method! |
Sorry, I spoke too soon. Here's the code I wrote... ` var expression = MRE.ToExpression(rule.RuleObject); ` |
First off, let me say that this is an excellent project! I have been able to do more in solving my business problem with your code than any other rules engine that I've researched and/or worked with!
I have a situation where I need to select groups of objects from a collection. For example, if I have a collection of programs of type TANF, SNAP and MED, in a collection, with your code, I've been able to create a rule that will evaluate true if the collection has all three or TANF & SNAP only or TANF & MED only or just TANF alone and false if TANF isn't included. This is exactly what I want with the rule. Yeah! While I am able to determine if collection elements satisfy the condition, currently I am unable to determine which elements were matched. What if I defined a rule that said "IF [TANF and SNAP or MED or TANF] or [LTC and SNAP or MED or LTC]", I would need to know if TANF matched or if LTC matched.
What I would like to do, is execute the expression against the collection, determine if the rule is satisfied AND be able to execute the rule to return back the matching results. Predicates and LINQ expression trees are new to me so I'm not sure if this is possible or not. What do you think? Is it possible?
Thanks,
Michael
The text was updated successfully, but these errors were encountered: