I'm trying to implement nHibernate mapping for a large exisiting system. trying to map the relationship between two object. One object is "Attachments" which relate to a number of different objects across the system. So in the database it has two columns which it uses to relate itself
ItemType
ItemId
If I have a product with attachments on then ProductId = ItemId and ItemType will be a predefined value E.g. '0001' Where as User object might be '0002', Order might be '0003' and so on for other ItemTypes.
Now I need to map this in nhibernate. So I want to have a collections of attachments on the Product Object but this means mapping it across both ItemId and ItemType
If it was just the ItemId mapping that was required it could do
HasMany(x => x.Attachments).KeyColumn("ProductId");
But Instead I need to map it where KeyColumn "ProductId" and ItemType in Attachments table is equal to '0001'
How could I go about this...?
Structure Product table
[Product]
ProductId
Name
Description
Attachment table
[Attachment]
AttachmentURL
ItemId
ItemType