Replies: 1 comment 1 reply
-
@ruwentos first, let me make sure it's clear why the exception is thrown from the RHS of the first rule that inserts the facts. When a new fact is inserted, it propagates through the Rete network, defined by the rules' patterns, and necessary expressions are evaluated. It is during this insertion of the new fact that the exception was thrown. Regarding the handling of nulls - as you noted, facts cannot be null. The best way to handle it is using a null object design pattern. Something along these lines: .Select(c => c.FirstOrDefault(r => condition) ?? Result.Empty) Where I also wanted to ask you for a favor and help me a bit by simplifying your examples and questions to be more generic, minimalistic reproduction scenarios. I'm sure your business domain for which you are trying to write rules is very important to you and is itself very complex. But it's hard for me to figure things out as I have to parse through all this domain complexity, which, honestly, is not related to NRules. It is also less useful to others if your questions are too focused on your domain. I would like the discussions on this GitHub project to be more about the features and capabilities of the engine itself. I hope you understand and take this into account moving forward. Thank you. |
Beta Was this translation helpful? Give feedback.
-
I changed a rule a bit to:
It throws an 'RhsExpressionError' 'Object reference not set to an instance of an object.' in 'Body = {ctx.Insert(new MatchAllResult(bankAccount, entry, investorAccount, cash))}'. This code belongs to a different rule that ran before and runs just fine without this rule.
I understand that 'FirstOrDefault' could return null. But also the function 'AddNewFact' did not made it up.
I then solved it by changing the rule to this:
My questions:
Is there a more easy way to not match a null object?
Beta Was this translation helpful? Give feedback.
All reactions