I have a scenario where we have a lookup table with an additional column. Were it not for this column then a simple many-to-many would save the bacon but but now I have to create a third class which of course is fine too. The problem here though is that I can't make cascading work and have to resort to calling Session.SaveOrUpdate(object) three times.
The classes looks like below:
public class ContactMap : ClassMap<Contact>
{
public ContactMap()
{
Id(x => x.Id);
HasMany(x => x.DeviceContacts)
.Table("lookup_table")
.KeyColumn("contact_id")
.AsSet()
.Inverse();
}
}
public class DeviceMap : ClassMap<Device>
{
public DeviceMap()
{
Id(x => x.Id)
.Not.Nullable();
HasMany(x => x.DeviceContacts)
.Table("lookup_table")
.KeyColumn("device_id")
.AsSet()
.Inverse();
}
}
public class DeviceContactMap : ClassMap<DeviceContact>
{
public DeviceContactMap()
{
CompositeId()
.KeyReference(x => x.Contact, "contact_id")
.KeyReference(x => x.Device, "device_id");
Map(x => x.UId, "contact_uid");
}
}
Now there has to be a better way of doing this. One thing that crossed my mind was to map the reference as well but that fails with too many parameters.