Consider these 3 tables:
Client
- Id
Product
- Id
Invoice_Row
- Id
- LinkedObjectId
- LinkedObjectType
Invoice_row refers to the tables above using LinkedObjectId and LinkedObjectType fields, for example:
Invoice_row ID = 1
- LinkedObjectId = 1 (meaning product id = 1)
- LinkedObjectType = 'Product'
Invoice_row ID = 2
- LinkedObjectId = 1 (meaning client id = 1)
- LinkedObjectType = 'Client'
As you can see, invoice_row has a dynamic key (meaning it’s really not a key) to the two other tables. It refers to the two other tables by first looking at the LinkedObjectType (which table to refer to) and then by LinkedObjectId (the specific ID in the referred table).
Yes I know this is bad, but this is a legacy data model I have to work with.
Is there any way this can be somehow mapped in a normal way (using either NH or EF), like this:
Client
Invoice_Rows
Product
Invoice_Rows
Thanks!
in NHibernate (using Fluentmapping)
then you can use it as simple association (except that you can only set mapped entities)