简体   繁体   中英

NHibernate - Composite-Id on relation - Where ID of parent is not same composite

Say I have these table in an Oracle database

Person:
PersonId <- PK ID (int, from sequence)
PersonFirstNameID <-- int
PersonLastNameID <-- int
PersonSecurityID <-- int

PersonDetails
PersonFirstNameID -CompositeKey
PersonLastNameID -CompositeKey
PersonSecurityID -CompositeKey
PersonDetailKey
PersonDetailValue
PersonDetailRisk

Now I want to model the one to many relation from Person to PersonDetails in NHibernate.

How can I do this? I've tried setting up a component representing the composite Id and feeding this into the one to many via the property ref however this generate SQL with duplicate columns and throws the following: System.ArgumentException: Identifier type mismatch; Found: Expected:

The NHibernate documentation talks only about doing this when the composite Id is the same on both..

Yes... Its not my DB schema, its a legacy DB and access is very limited.

Not quite clear.

For a foreign key relationship to work, the child must reference the primary key of the parent, so the data structure suggests that the primary key of person is FirstNameId/lastNameid/securityid (and hence your best move would be to ignore the personid column).

Is the Person_Id actually the primary key (defined as a PK in the DB), or is the database's version of PERSON primary key actually FirstNameId/lastNameid/securityid ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM