I currently have the following (simplified) class / db schema:
Entity Prospect Customer
+- Id +- Id +- Id
+- Address +- Entity +- Entity
+- Name +- ... +- ...
+- ...
ENTITY PROSPECT CUSTOMER
====== ========== ========
ID - INT PK ID - INT PK ID - INT PK
ADDRESS - VARCHAR ENTITY_ID - INT FK ENTITY_ID - INT FK
NAME - VARCHAR ...
...
Along with the following fluent mapping:
PROSPECT_MAP:
Table("PROSPECT");
Id(x => x.Id).GeneratedBy.Increment();
References(x => x.Entity).Cascade.All().Fetch.Join().Column("ENTITY_ID");
...
CUSTOMER_MAP:
Table("CUSTOMER");
Id(x => x.Id).GeneratedBy.Increment();
References(x => x.Entity).Cascade.All().Fetch.Join().Column("ENTITY_ID");
...
Now there are also a bunch of stuff attached to the entity (using entity_id as a FK). In my application, a prospect can become a customer.
Hence I would like to create a new Customer, link it to the entity_id used by the ex-prospect (so that all info related to that entity now belong to the customer) and then delete the prospect from the database (so basically just remove the entry from the prospect table and not cascade down to its child components which are now linked by the newly created customer)
Is this possible with NHibernate? Note that I need the cascade.all in my ProspectMap as deleting a prospect along with its components should remain an option in the app.
Thanks a lot.
1 Answer