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 Fluent NHibernate mappings?
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);
}