Is it ever valid to convert an object from a base class to a subclass
inheritance, nhibernate
Solution
As long as your business model matches your domain, you're doing the right thing.
However, it sounds to me like you should have something like:
Manager Promote(Employee employee)
{
var manager = new Manager();
//promote your employee to a manager here
return manager;
}
inside some workflow process of some sort.
In regards to NHibernate, it sounds like you're mixing your ORM logic with your business domain. Promoting an Employee to a Manager is a business domain construct, and as such belongs in your business model. However, how NHibernate maps your Employees and your Managers into your DB has nothing to do with your business model, except for how to map them over. This definitely doesn't have anything to do with how to promote an employee to a manager, though.
Problem
In my application at the moment I have (as in so many other applications) an entity called `Contact`, which represents any person. At its most basic level this is used to represent business contacts. However it can also be used to represent employees of the company. and there are also a couple of special types of employee (let say there is one called `Manager`) I am attempting to model this as an inheritance relationship which makes sense. Employees have names and addresses just like contacts, as well as a number of employment related attributes. Managers also have a number of manager specific attributes. The difficulty comes when an employee gets promoted to a manager. Is it ok to convert the base class `Employee` to the inheriting class `Manager`? It feels wrong. I guess I would do it with a specialised constructor on `Manager`. As an aside does NHibernate support this kind of behaviour? is it as simple as getting the employee, creating the manager from the employee, then saving the manager?