R – Fluent Nhibernate composed entity, specify parent key


In this question I was answered hot to map a composed entity from the primary key of the table.
So given:

public UserMap()
    Id(x => x.Id, "UserId")
    Map(x => x.Name, "UserName");
    Map(x => x.Login, "LoweredUserName");
    WithTable("LdapUsers", m => {
          m.Map(x => x.FullName, "FullName");

everithing works if in the "LdapUser" and in the "aspnet_Users" there is a column named "UserId".

What If I want to specify both the colum name for the foreign key table and the column name for the key from the main table as this is not the pk so use another column to do the join?

Best Solution

It looks like this is not currently supported at all in NHibernate. There is an open issue for it on NHibernate's JIRA. Actually, I think this is for collections but probably applies for what you're doing as well. The idea is you would add a property-ref attribute on your <key> element that points to the property you want to reference instead of the primary key.

Supposedly the change is already available in the Alpha2 release of NHibernate 2.1.0. Of course, it might be sometime after NH2.1 is a general release before this gets added to FNH. If you can, I would recommend getting a hold of the Alpha2 release and trying it with your situation. If it doesn't work for your composed entity, only collections, you might want to submit another issue on JIRA so it gets added as well.

Related Question