session.Refresh() isn't going to do it becaus the collection is lazily loaded. you are probably running into first level session cache issues-- second-level cache issues if you've got that enabled as well. so here are a few suggestions:
Initialize the child collection:
Code:
if(true)
{
-- hire I want undo changes that was made above (I needn't save changes!)
session.Refresh(class1);
HibernateUtil.Initialize(class1.Collection1);
}
this isn't the best solution because you'll have to do the same for class1.Collection2, etc. another alternative is to:
Code:
if(true)
{
-- hire I want undo changes that was made above (I needn't save changes!)
session.Lock(class1, LockMode.Read);
}
this forces NH to sync the "in-memory" object with the database, reading the database and discarding the in-memory changes. however, this is more accurately used for reattaching an object to a new session. the next time you use your collection, it should load the collection from the db.
you could simply "reload" the object. this is probably your best bet:
Code:
if(true)
{
-- hire I want undo changes that was made above (I needn't save changes!)
session.Evict(class1); // or session.Clear()
class1 = session.Load(typeof(Class1), id);
}
i don't think Memento would work here because you aren't supposed to replace an entire collection....
-devon