user610217
user610217

Reputation:

Does NHibernate support referencing unique columns that are not the primary key?

I'm afraid I may be asking a stupid question here, but my google-fu seems to be suffering. Most RDBMS's support creating a foreign key referencing a unique key in another table that is not the primary key, but I can't seem to find a "how-to" on this for NHibernate. I assume because everyone assumes it's stupid-easy.

Is this supported? Are there any caveats? What would an XML mapping look like for that?

Upvotes: 2

Views: 426

Answers (1)

Claudio Redi
Claudio Redi

Reputation: 68410

If I understand well your question, property-ref is what you're looking for

From Nhibernate docs (5.1.12. Many-to-one)

property-ref (optional): the name of a property of the associated class that is joined to this foreign key. If not specified, the primary key of the associated class is used.

I personally don't know any caveats but Ayende Rahien, an active member of NHibernate development team, strongly suggest to avoid this if possible. He doesn't say why, probably just because is ugly :)

Upvotes: 3

Related Questions