문제

Is there a way to map property with database column with custom column, that IS NOT a FK, just a candidate key ( it is unique for table )?

If not, what is my options here? (need to restrict select results with joined table restrictions)

도움이 되었습니까?

해결책

NHibernate supports feature called property-ref. It is documented here: 5.1.10. many-to-one. Some extract:

The property-ref attribute should only be used for mapping legacy data where a foreign key refers to a unique key of the associated table other than the primary key. This is an ugly relational model. For example, suppose the Product class had a unique serial number, that is not the primary key. (The unique attribute controls NHibernate's DDL generation with the SchemaExport tool.)

So, if the child table contains for example Guid, which is the same as in the target parent table... this could solve the issue. Example mapping:

<many-to-one name="Parent" property-ref="ParentGuid" column="THE_GUID_COLUMN"/>

Using the fluent syntax, it could look like this:

References(x => x.Parent)
    ...
    .PropertyRef("ParentGuid")
    .Column("THE_GUID_COLUMN");

Anyhow, this is not ideal and should be used mostly for solving legacy stuff.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top