views:

241

answers:

1

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

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

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?

A: 

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.

Stuart Childs