Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate - how to configure associations not to use primary key

I'm working with a legacy database put together by some very strange people. I'm writing an NHibernate DAL over the top of it but running into some odd mapping scenarios.

In one example, I have a table with a number of fields including LE_RECNUM (integer primary key) and LE_CODE (string).

However, all relationships throughout the database join onto LE_CODE, not LE_RECNUM, for some unfathomable reason.

I need to specify that LE_RECNUM is the Id in my mapping file, because I need the primary key to be generated when I insert records. However, I want all associations to use LE_CODE instead of LE_RECNUM.

Can anyone suggest how I might do this?

like image 823
David Avatar asked Feb 24 '23 12:02

David


1 Answers

References(x => x.SomeProperty).Column("LE_CODE").PropertyRef(x => x.SomePropertyInParent);
like image 179
cremor Avatar answered May 01 '23 08:05

cremor