Short answer: you can't. See http://stackoverflow.com/questions/594187/nhibernate-inheritance-problem-when-saving-childs Try redesigning that part of the domain so it doesn't use inheritance.
A very ugly workaround is to use SQL to make the necessary changes to change a type. On Aug 24, 11:50 am, profquail <[email protected]> wrote: > Hi all, I've been using Castle ActiveRecord for about a year now, but > I've run into a somewhat complicated problem that I can't find an > answer to. > > In my object model, I've got a class called "Estimate" (which is > derived from ActiveRecordBase<T>). When we do a price quote for a > customer, it is entered into our system and saved as this object. > Later on, if the customer wants to go ahead with the work, the > Estimate is promoted to a more specific type "WorkOrder". The > WorkOrder class is derived from Estimate, and simply adds some extra > fields for notes and scheduling information. > > I'm porting this model over to ActiveRecord so that we can clean up > our codebase a bit. However, I can't seem to find a way to "promote" > the Estimate object into a WorkOrder. I couldn't find anything built- > in to ActiveRecord or NHibernate to do this, so I wrote my own > reflection code to copy the object, but when I call Save() on the new > WorkOrder object (copied from the estimate, so they share the same Id > number), I get an ActiveRecordException saying "Could not perform Save > for WorkOrder", with an InnerException message of "a different object > with the same identifier value was already associated with the > session: 395, of entity: MyCompany.WorkOrder" > > The database table is set up to use table-based inheritance (one table > for Estimate, and another for WorkOrder, which only contains the extra > fields). > > Is there any way to solve this problem? It seems like I'm close, but > I'm pretty stuck at this point. I tried evicting the Estimate object > from the current SessionScope after copying the data into the > WorkOrder, but that didn't fix it either. > > Thanks for any help you can offer. > > Regards, > Jack --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
