1

Using NRules, I want to be able to create a session, insert facts, have it fire and complete, and while the session is still alive in memory (static variable) I want to call an update on the fact.

private static ISession session;  //this is instantiated when bulding the rules dinamically
public void RulesTest(RulesTest command)
    {
        //entities holds ALL facts ever inserted in session
        var entities = _session.Query<Entity>();
        _session.Insert(command.Fact);

        Rule rule = GetRule();
        _session.Insert(rule.Condition);
        _session.Insert(rule.Action);

        _session.Fire();
    }

This fires the rule and does everything properly. What I want now to happen is to add the capibility of being able to update the SAME FACT that was fired once, but now with a new value...meaning, I want to update the fact, and have it run through the conditions again.

Doing _session.Update(command.Fact) after updating my fact gives me an error message: "Fact for update does not exist", even though I can see ALL facts still in session.

Any idea is welcome. Thank you.

Jose
  • 1,130
  • 3
  • 15
  • 25

1 Answers1

1

I figured out how to do it if anyone else runs into this problem. Preserving ISession (in the manner described above), use _session.Query<Facts>() in order to inspect what you already have. Manipulate your code to make an update on this object. After that call

_session.TryUpdate(Fact);
_session.Fire();

And it works :)

Jose
  • 1,130
  • 3
  • 15
  • 25