I have three entities: Customer, Device and LocationTag.
Customers have a list of LocationTags (nothing more than an ID and a
Description). They also have a list of Devices.
Devices are tagged with a subset of the Customer's LocationTags, so
Devices have a List of LocationTags, too (but only of the Customer's).
If I delete a LocationTag from the Customer's list, I would like it
also to cascade delete from the list of LocationTags in the Device.
Currently, I have it working but with manual code in the domain object
classes, but violates DRY in my opinion.
Is it possible to accomplish this via NHibernate?
Better question is whether or not these should even be attempted in
NHibernate as opposed to putting that logic in the domain object(s).
Simplified Fluent NHib mappings:
Customer
public CustomerMap()
{
WithTable("Customers");
Id(x => x.ID)
.WithUnsavedValue(0)
.GeneratedBy.Identity();
Map(x => x.Name);
HasMany<LocationTag>(t => t.LocationTags).IsInverse();
HasMany<Device>(d => d.Devices).IsInverse();
}
Device
public DeviceMap()
{
WithTable("Devices");
Id(x => x.ID)
.WithUnsavedValue(0)
.GeneratedBy.Identity();
Map(x => x.Name);
HasMany<LocationTag>(x => x.LocationTags).IsInverse();
}
LocationTag
public LocationTagMap()
{
WithTable("LocationTags");
Id(x => x.ID)
.WithUnsavedValue(0)
.GeneratedBy.Identity();
Map(x => x.Description);
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---