I have a common superclass (suppose it’s Employee), which has (amongst others) subclasses Engineer and Salesman.
The table structure of the Employee classes are modelled using table-per-hierarchy.
A Department object references both salesmen and engineers:
public class Department
{
public IEnumerable<Engineer> Engineers { get; set; }
public IEnumerable<Salesman> Salesmen { get; set; }
}
The problem occurs when I empty the Engineers collection from the Department:
- When both relationships are mapped with
cascade=noneorcascade=all(on theDepartmentside), then all theSalesmanrecords get their foreign-key set to null (here is the statement generated by nHib:UPDATE dbo.Employee SET Department_id = Null WHERE Department_id = @p0;. - When both relationships are mapped with
cascade=all-delete-orphanthen I get anObjectDeletedExceptionreferring to a completly different collection of theDepartmentobject (can’t figure this one out) - when mapped with
cascade=allorcascade=noneand table per subclass strategy, all seems to be working fine - when mapped with
cascade=all-delete-orphanand table per subclass strategy, I once again get theObjectDeletedExceptionreferring to a completly different collection of theDepartmentobject
obviously I’m missing some nHib basic here.. but what is it?
duhh….
inverse=trueon the parent class for those collections.still not sure what caused that seemingly-unrelated
ObjectDeletedExceptionthough…