views:

48

answers:

0

Hello all,

I want to have a centralize place to check for inserts or updates to an object, and for certain scenarios, I want to update it's parent based on the information from the child. I have the following code in my event listener:

    public bool OnPreInsert(PreInsertEvent @event) {
        UpdateCalcs(@event.Entity);
        return false;
    }

    public bool OnPreUpdate(PreUpdateEvent @event) {
        UpdateCalcs(@event.Entity);
        return false;
    }

    private static void UpdateCalcs(object entity) {
        var A = entity as TypeA;
        if (A.Type == "Example") {
            var list = session.CreateCriteria<TypeB>("b")
               .Eq("b.Event", A.Event)
               .List<TypeB>();

            // do processing based on list
        }
    }

I've been having trouble with the call CreateCriteria(). It doesn't really provide me with any exception message. So first of all I want to know if I can use CreateCriteria() within an eventListener, and if it is possible, is there anything special I need to do in order to use it correctly? Thanks in advance for any help!