views:

141

answers:

0

Given the following object model

class Test
{
...
    public string Name {get;set;}
    public IList<Test2> Collection {get;set;} //mapped with cascade="all"
}

class Test2
{
...
    public string Name {get;set;}
}

and code sample

var test = new Test();
test.Collection.Add(new Test2(){Test=test,Name="1"});

//saving new entity with NHibernate

test.Name="2";
test.Collection[0].Name="2";

// updating entity with NHibernate
using(var session = getSession())
using(var transaction = session.BeginTransaction())
{
    session.SaveOrUpdateCopy(test);
    transaction.Commit();
}

I want to have log of changes of the collection as part of log entity "test"

something like: - Changes to: Test. * Change property "Name". Old value: "null" New value: "2" <- this can be made via event listeners * Change to collection Collection <- at least this

I don't know how I can accomplish this . May be proper setup of listeners? But I can't determine, which listener can catch collection changes in second call to SaveOrUpdateCopy