Why aren't you deleting the address first, thus no orphans occur? I guess
I wasn't really aware you could cause orphans in this way, but I guess it
makes sense.
It seems to me that you need to write a function to see if the address is
still used by either the Person or the Organisation objects. And if not
then Delete the address, otherwise keep the address.
Another design may be to have OrganizationAddresses and PersonAddresses
objects that are different from each other.
Matt
On Monday, September 1, 2014 9:04:18 AM UTC-5, David Perfors wrote:
> Hello,
>
> We have the following table structure:
> | Address |
> -----------
> | Id |
> | Street |
> | City |
> -----------
>
> | Person |
> -----------------------
> | Id |
> | Name |
> | VisitingAddressId |
> | PostalAddressId |
> | <Some extra fields> |
> -----------------------
>
> | Organisation |
> -----------------------
> | Id |
> | Name |
> | VisitingAddressId |
> | PostalAddressId |
> | <Some extra fields> |
> -----------------------
>
> Basically our objects are modelled the same way. The Person and
> Organisation are completely different and should not inherit from each
> other in any way.
> The mapping we use is basically the following (both Person and
> Organisation have a similar mapping):
>
> public class PersonMap : ClassMap<Person>
> {
> public PersonMap()
> {
> Id(x => x.Id);
> Map(x => x.Name);
> References(x => x.VisitingAddress).Cascade.All();
> References(x => x.PostalAddress).Cascade.All();
> }
> }
>
>
> From address there is (at the moment) no mapping to either Person or
> Organisation.
> Since the visiting has a public setter, the addresses could be overridden
> by replacing the address instance with a new instance of Address, when
> saving the Person or Organisation, the original address will be orphaned.
> Is there a way (other than making the setters non public) to prevent this?
>
> Kind regards,
> David Perfors
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.