Woil wrote:
I'm working on updates to the Interceptor that I'll be posting to the JIRA as soon as it is back online that relate specifically to deleting objects.
To answer your basic question, in your custom interceptor (which should be inherited from EmptyInterceptor instead of implementing the IInterceptor interface if possible) simply access your session as usual. For example:
Code:
public override void OnDelete(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
if(entity is IDeletedMyParents)
{
entity.ParentObject.ForeignKey = null;
NHibernateHelper.GetCurrentSession().Save(entity.ParentObject);
}
}
However, it seems like you're probably working against your own schema here, and really should update that instead. You probably don't have your cascade attributes set correctly in the schema...
I'm a bit confused about your solution...the entity that is being deleted is the parent object, so that is what is passed into OnDelete. Your solution makes it look like the child entity is passed in during the OnDelete.
As for the cascade, I'm assuming you are talking about a cascade from the parent to the children on the database schema? I'm not a big fan of database triggers or cascades as I see them as business rules that should be in the application...I'm one of those "databases should just be a data store" guys :) So, I need to implement this cascade in the .NET code, and I'm looking for a way to do it...I had no idea you could call NHibernateHelper to get the current session...that may be what I am looking for, but on the other hand I've seen it written that messing with the session using an interceptor is not a good idea...and thoughts on that?