I've attached an IPreUpdateEventListener to nhibernate and not getting the results I expect (saving of a child object). This object has history attached to it and if certain things change, it needs to reflect this and save it, no big deal right? Given the entity as such -- assume ListOfHistory is newed up in a constructor ...
public class Car : IHaveHistory
{
//impl of IHaveHistory
public void AddHistory(string message, int parentId)
{
ListOfHistory.Add(new CarHistory { Message = message, ParentId = parentId });
}
public ISet<CarHistory> ListOfHistory { get; private set; }
}
public class CarHistory
{
public int ParentId { get; set; }
public string Message { get; set; }
}
... in some other class ...
public bool OnPreUpdate(PreUpdateEvent beforeUpdateEvent)
{
//greatly watered down ... but effectively ...
var car = beforeUpdateEvent.Entity as IHaveHistory;
if (car != null)
car.AddHistory(someId, aMessage);
return false;
}
The OnPreUpdate event fires, takes the entity, assures its the expected type (IHaveHistory) and determines if certain properties have changed or not based on some attributes. If it is, it adds a new history object to the ListOfHistory collection. Not rocket science.
What is confusing me the most is the entity HAS this history record, all the way from the time the event tags it on and all the way back to the controller -- but it simply does not save. There's no errors tossed and worse - if I manually add this history object it saves, no problem (so I know my mappings are good).
I'm at a loss, any ideas?